声明OC的头文件在Swift中使用实际上分为两种情况:
一种是对于一个应用本身(App Target),我们需要声明 Objective-C Bridging Header
- In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.
In Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting has a path to the bridging header file. The path should be relative to your project, similar to the way your Info.plist path is specified in Build Settings. In most cases, you won't need to modify this setting.
另一种是作为一个静态库(Framework Target),我们需要使用 Umbrella Header
,这样所有的Swift文件就会自动识别所有被声明的 OC 头文件,并且Swift文件不需要再次引入声明 "import statements"
Under Build Settings, in Packaging, make sure the Defines Module setting for the framework target is set to Yes.
- In the umbrella header, import every Objective-C header you want to expose to Swift.
更多详细的信息可以参考 Importing Objective-C into Swift