Obj-C 的 Swift 桥接头

标签 swift swift2 cocoapods bridging-header cardio

我已经通过 CocoaPods 安装了 Card.IO。我的工作区看起来设置正确,我看到了 Card.IO Objective-C 头文件,但是,在我的主要 Swift 项目中,我尝试引用任何 Card.IO 类 - 我收到未解析的标识符错误。

编辑 我的理解是 Xcode 找不到桥接头:

#import "CardIO.h"

@import AudioToolbox;
@import AVFoundation;
@import CoreMedia;
@import CoreVideo;
@import MobileCoreServices;

文档说明

In Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting under 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 should not need to modify this setting.

这对我来说没有意义 - 所以不确定路径放在哪里?我已将以下内容添加到 Build Settings > Search Paths > Header Search Paths > Debug & Release

MyApp/MyApp-Bridging-Header.h

但这似乎是不正确的?

最佳答案

在这里找到答案

https://bohemianpolymorph.wordpress.com/2014/07/11/manually-adding-a-swift-bridging-header/

In your project build settings, find Swift Compiler – Code Generation, and next to Objective-C Bridging Header add the path to your bridging header file, from the project’s root folder. So it could by MyProject/MyProject-Bridging-Header.h or simply MyProject-Bridging-Header.h if the file lives in the project root folder.

关于Obj-C 的 Swift 桥接头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33862259/

相关文章:

ios - 如何解决显示类似文件名被使用两次的错误

ios - 滚动时 TableView 重新排列/创建空白单元格。 swift

ios - CocoaPods 1.0.1 仍然需要与 Swift 桥接 header

json - 使用第 3 方库 swift 4 提取 JSON 数据

cordova - Ionic Cordova 平台添加 ios 失败,库未加载 :/usr/local/opt/openssl/lib/libssl. 1.0.0.dylib (LoadError)

ios - Swift:不能用类型索引下标 [String:NSObject] 的值?

swift - 碰撞检测 Spritekit 位掩码

ios - 将属性传递到 UIView 中的 drawRect 时遇到问题

iOS UIImagePickerController 如何在从相机拍摄图像后立即保存图像

swift - Switch 语句中 Case 的顺序对 Swift 中的执行速度有影响吗?