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

时间:2016-01-01 05:05:41

标签: ios objective-c swift2 cocoapods libjingle

我正在尝试将libjingle_peerconnection框架导入到我的Xcode项目中,但出于某种原因,我无法在Swift源文件中导入带有import RTCICEServer的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

enter image description here

1 个答案:

答案 0 :(得分:9)

<强> 1。创建xxx-Bridging-Header

使用您选择的方法为项目添加桥接标头,最简单的方法是创建单个<img/>文件并在此对话框中回答创建桥接标题

Create Bridging Header

<强> 2。在桥接标题中引用您的Pod

包含您的文件:

.m

第3。 Objective-C暴露于Swift

一旦进入桥接头,就不需要在Swift中导入Obj-C类。直接使用这些:

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

#import "RTCICEServer.h"

另一个例子是here

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