在 iOS 应用程序中,我有一个子项目(不是 cocoapods),其中包含一个 swift 文件和 ObjC 文件(由 swift 文件使用)。 XCode 自动创建了一个桥接文件但无法构建它,因为在框架中显然不允许桥接。我使用的解决方法是将 objective-c header 添加到 umbrella 文件并且它起作用了。现在我需要使用 ObjC 的 swift 类。我有 define module
设置为 YES,生成的文件 Framework-Swift.h 。但是当我尝试在 objective-c 中导入它时,我得到了
Could not build Objective-C module
我在谷歌搜索后得到的最接近的答案是:
Ah gotcha. It looks like you're building a mixed Swift & Objective-C pod - if that's the case, Xcode will try to import within the generated -Swift.h header. You'll need to create the header manually and add imports for the Objective-C classes that you want to expose to Swift.
CocoaPods generates an umbrella header automatically and imports it within the .modulemap, but Xcode doesn't use that when generating the -Swift.h header
但我不确定需要手动创建什么 header 。 关于在 objective-c 框架中使用 swift 的任何想法或指示?两种方式?
最佳答案
在包含多个目标的 Swift 项目中使用 Swift pod 时,我也遇到了类似的问题。根本没有 Objective-C 代码。我试图清除构建文件夹、pods 缓存、派生数据 - 没有任何效果。
解决方法:
打开包含模块代码的目标的build设置。将“安装 Objective-C 兼容性 header ”设置为“否”
关于ios - 在 objective-c 模块中使用 swift 时无法构建 Objective-C 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55651552/