ios - 用swift语言的项目怎么避免多个文件import相同的包?
怪我咯
怪我咯 2017-04-18 09:05:08
0
5
637

比如有两个ViewController,在第一个ViewController文件import CoreLocation之后,在第二个ViewController文件不import CoreLocation的话没法用CoreLocation,import的时候CoreLocation上面有道横线。

新建了一个工程,试了一下,还是不好使,不import系统的库就提示有错误

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
巴扎黑

You can create a swift file in the project to import external files. There is no need to import elsewhere.

Peter_Zhu

There is no need to think about this issue. Because all Swift files are global and can be called without import. Just drop it directly, no need to import

洪涛

Actually, I don’t understand it too well
In the same namespace, you can directly reference it without import

When I was in OC, there was a PrefixHeader that specifically imported a class and was universal
But Swift doesn’t have this thing. I know it can be implemented using bridging

I installed several common libraries in pod
I found that SDWebImage only needs to be imported once, and all classes can be used
But other libraries still seem to need to be imported every time

Sit and wait downstairs

刘奇

To import a swift file into OC, don’t you need a bridge file? Just write the import in the bridge file. All other swift files in the entire program can be used directly. That’s how swift is.

Ty80

That would be great. Similarly, you can look at Java, Python, etc., and you can also explicitly indicate which packages you use in this file. import 的地方 import

Of course, if you are worried that using

multiple times will cause the app size to increase, then you are worrying too much. import

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template