Import Objective-C Framework (CocoaPod) into Swift?

你。 提交于 2019-12-21 09:13:39

问题


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. 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


回答1:


Bridge

1. Create a 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:

2. Reference your Pod in the bridging header

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

Once in the bridging header, you need not import the Obj-C classes in Swift. 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.



来源:https://stackoverflow.com/questions/34553684/import-objective-c-framework-cocoapod-into-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!