如何在全球范围内导入Swift框架? [英] How to import a Swift framework globally?
问题描述
我希望有一种方法可以在每个班级全球导入我的Swift Cocoapods,我怎样才能实现这一目标?
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 I haven't tried and thought may be possible if found a way to work them:
有一个像UIKit这样的一般导入语句并将所有内容放在那里。 (编辑:失败了)
Have a general import statement like UIKit and put everything in there. ( This failed)
以某种方式将Swift框架放在Obj-C briding header中并导入那里的东西。
Somehow put Swift frameworks in the Obj-C briding header and import the stuff in there.
推荐答案
在Swift中强烈建议不要这样做,因为这会在模块之间引入隐式耦合。
It's strongly discouraged in Swift because that would introduce implicit coupling between modules.
但是,您可以通过在导入其他模块的模块中声明 typealias
来全局使用某个符号:
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
这篇关于如何在全球范围内导入Swift框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!