Implicitly import specific Swift module

前端 未结 2 1750
囚心锁ツ
囚心锁ツ 2020-12-09 20:04

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 ove

相关标签:
2条回答
  • 2020-12-09 20:49

    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.

    0 讨论(0)
  • 2020-12-09 20:53

    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.

    0 讨论(0)
提交回复
热议问题