Reputation: 4676
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.
Upvotes: 12
Views: 6111
Reputation: 4676
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.
Upvotes: 37
Reputation: 19544
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.
Upvotes: 4