9

我正在尝试将libjingle_peerconnection框架导入我的 Xcode 项目,但由于某种原因,我无法import RTCICEServer在 Swift 源文件中导入 Objective-C 标头。我试图使用头文件等。我做错了什么?

# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!

target 'VideoRTCTest' do
    pod "libjingle_peerconnection"
end

target 'VideoRTCTestTests' do

end

target 'VideoRTCTestUITests' do

end

在此处输入图像描述

4

1 回答 1

9

1. 创建一个 xxx-Bridging-Header

使用您选择的方法将桥接头添加到您的项目中,最简单的方法是创建单个文件并在此对话框中.m回答Create Bridging Header :

创建桥接头

2. 在桥接头中引用你的 Pod

像这样包含您的文件:

//
//  Use this file to import your target's public headers that
// you would like to expose to Swift.

#import "RTCICEServer.h"

3. Objective-C 暴露给 Swift

进入桥接头后,您无需在 Swift 中导入 Obj-C 类。直接使用这些:

let uri = URL(fileURLWithPath: "")
let rtc:RTCICEServer = RTCICEServer(uri: uri, username: "", password: "")
print(rtc)

这里描述了另一个例子。


► 在GitHub 上找到此解决方案,并在Swift Recipes上找到更多详细信息。

于 2016-01-14T21:53:36.590 回答