簡體   English   中英

將Objective-C Framework(CocoaPod)導入Swift?

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

我正在嘗試將libjingle_peerconnection框架導入到我的Xcode項目中,但由於某種原因,我無法在Swift源文件中import RTCICEServer帶有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

在此輸入圖像描述

1.創建一個xxx-Bridging-Header

使用您選擇的方法向項目添加橋接頭,最簡單的方法是創建單個.m文件並回答創建橋接頭到此對話框:

創建橋接標題

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的其他詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM