简体   繁体   English

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

[英]Import Objective-C Framework (CocoaPod) into Swift?

I'm trying to import the libjingle_peerconnection framework into my Xcode project, but for some reason I can't import the Objective-C header with import RTCICEServer in Swift source files. 我正在尝试将libjingle_peerconnection框架导入到我的Xcode项目中,但由于某种原因,我无法在Swift源文件中import RTCICEServer带有import RTCICEServer的Objective-C头。 I have attempted to use header files, etc. What am I doing wrong? 我试图使用头文件等。我做错了什么?

# 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

在此输入图像描述

Bridge

1. Create a xxx-Bridging-Header 1.创建一个xxx-Bridging-Header

Add a bridging header to your project using the method of your choice, the easiest one being creating a single .m file and answering Create Bridging Header to this dialog: 使用您选择的方法向项目添加桥接头,最简单的方法是创建单个.m文件并回答创建桥接头到此对话框:

创建桥接标题

2. Reference your Pod in the bridging header 2.在桥接标题中引用您的Pod

Include your files as so: 包括您的文件如下:

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

#import "RTCICEServer.h"

3. Objective-C exposed to Swift 3. Objective-C暴露于Swift

Once in the bridging header, you need not import the Obj-C classes in Swift. 进入桥接头后,您无需在Swift中导入Obj-C类。 Use these directly: 直接使用这些:

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

Another example is described here . 这里描述另一个例子。


► Find this solution on GitHub and additional details on Swift Recipes . ►在GitHub上找到此解决方案以及有关Swift Recipes的其他详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM