Import Objective-C Framework (CocoaPod) in Swift?

I am trying to import the libjingle_peerconnection structure into my Xcode project, but for some reason I cannot import the Objective-C header with import RTCICEServer into the Swift source files. I tried using 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 

enter image description here

+7
ios objective-c swift2 cocoapods libjingle
source share
1 answer

Bridge

1. Create an xxx bridge header

Add the bridge title to your project using the method you have chosen, the simplest of which is to create a single .m file and answer to Create a title for the header in this dialog box:

Create jumper header

2. Link to Pod in the title bar

Include your files like this:

 // // Use this file to import your target public headers that // you would like to expose to Swift. #import "RTCICEServer.h" 

3. Objective-C is exposed to Swift

Once in the bridge header you don't need to import the Obj-C classes into Swift. Use them 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 more about Quick Recipes .

+8
source share

All Articles