I use a third party Swift framework in my Swift app very often and would like to use it without having to write import ModuleName
in every single Swift file over and over again.
Is there a way to specify default imports like it was possible in Objective-C using a .pch
file?
I already checked Xcode build settings and swiftc
flags but none of them offers this functionality.
The @_exported attribute starts with an underscore. That means it's a private Swift attribute. Not a feature, an implementation detail. In short, this attribute lets you export a symbol from another module as if it were from your module.
Import order does not matter. If a module relies on other modules, it needs to import them itself.
Import Swift code into Objective-C within the same framework: Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes. Import the Swift code from that framework target into any Objective-C .
Actually there's a very easy workaround I could have thought about earlier…
Simply add the following to your app project's Objective-C bridging header:
@import ModuleName;
Swift will pick it up too! No need for import ModuleName
in every Swift file where you intend to use the module.
No, there is no Swift analogue for Objective-C .pch
files.
One could ostensibly reduce the number of import statements by creating an umbrella target framework that includes a number of other modules, but there's no way to avoid explicit imports of dependent modules outright.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With