导入Objective-C框架(CocoaPod)到Swift吗? [英] Import Objective-C Framework (CocoaPod) into Swift?

查看:137
本文介绍了导入Objective-C框架(CocoaPod)到Swift吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将libjingle_peerconnection框架导入我的Xcode项目,但是由于某些原因,我无法在Swift源文件中使用import RTCICEServer导入Objective-C标头.我试图使用头文件等.我在做什么错了?

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.创建一个xxx-Bridging-Header

使用您选择的方法向您的项目添加桥接头,最简单的方法是创建一个.m文件,然后在此对话框中回答创建桥接头:

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.在桥接标题中引用您的Pod

按原样包含您的文件:

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

#import "RTCICEServer.h"

3.暴露给Swift的Objective-C

一旦在桥接头文件中,您就无需在Swift中导入Obj-C类.直接使用这些:

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.

►在 GitHub 上找到此解决方案,并在

► Find this solution on GitHub and additional details on Swift Recipes.

这篇关于导入Objective-C框架(CocoaPod)到Swift吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆