I want to have a way to import my Swift Cocoapods globally in every class, how can I achieve this?
I tried a lot of things and they didn\'t work. Here are some ways
It's strongly discouraged in Swift because that would introduce implicit coupling between modules.
However, you can make a certain symbol available globally by declaring a typealias
in the module that imports the other module:
import ModuleName
public typealias ClassName = ModuleName.ClassName
A reason you wouldn't want to do this:
Imagine if both your frameworks would use the same method name, it would make things ambiguous for the compiler.The compiler won't know which method it should run.
To find out more see this question
There is no way to do this. And this is not a bug, this is a language feature (so far, as speaking of Swift 2.2).
Swift uses modules (Apple introduced them in Xcode 5 for Objective-C) and each file is an semantic unit, so you need to explicitly inform Xcode which modules are exposed to defined file.
Not only there is no support for your described behaviour, but you shouldn't also try to bypass it. Using unnecessary (unused) modules could theoretically produce slower code (taking into account that compiler uses this information to its optimisation process).
You can manually achieve the same functionality by:
#import <UIKit/UIKit.h>
to the Objective-C Bridging Header file (so that you don't need to repeat this for every single .swift file).for pods you have to do like #import <SwiftyJSON/SwiftyJSON-umbrella.h>
You should be able to import it globally by adding @_exported before the import.
@_exported import Podname
However, like the previous posters mentioned, this is not recommended.
As of Swift4:
I just managed to do that by adding the following line to my bridging header:
#import <PodName/PodName-Swift.h>
How good/bad this practise is? Not sure, but I just wanted some extensions globally available in my project. this did the trick.