将Objective-C Framework(CocoaPod)导入Swift?

Lev*_*iXC 9 objective-c libjingle ios cocoapods swift2

我正在尝试将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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Swi*_*ect 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"
Run Code Online (Sandbox Code Playgroud)

3. Objective-C暴露于Swift

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

let uri = URL(fileURLWithPath: "")
let rtc:RTCICEServer = RTCICEServer(uri: uri, username: "", password: "")
print(rtc)
Run Code Online (Sandbox Code Playgroud)

这里描述另一个例子.


►在GitHub上找到此解决方案以及有关Swift Recipes的其他详细信息.