[英]Building a Cocoapod with Swift and dependency on Objective-C framework
[英]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.