ios - 在 objective-c 模块中使用 swift 时无法构建 Objective-C 模块

标签 ios objective-c swift xcode bridging-header

在 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 ”设置为“否”

enter image description here

关于ios - 在 objective-c 模块中使用 swift 时无法构建 Objective-C 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55651552/

相关文章:

swift - 获取两个字符串之间的字符串 Swift

ios - 表格 View 加载缓慢

iphone - MKMapView 使用的投影是什么?

ios - 从 Nib 加载 UIView,手动调用 autolayout

objective-c - 是什么让符号变得懒惰或非懒惰?

ios - 重用 AFHTTPRequestOperation Manager 的优缺点是什么?

ios - Xcode 12.0 中是否有任何更改将 ButtonType 从 roundedRect 更改为系统?

objective-c - 将 Objective-C POST 请求转换为 Swift

ios - 强制更改 UINavigationController 方向

ios - ld:-no_pie和-bitcode_bundle(Xcode设置ENABLE_BITCODE = YES)不能一起使用错误