【问题标题】:Import Objective-C Framework (CocoaPod) into Swift?将 Objective-C 框架(CocoaPod)导入 Swift?
【发布时间】:2016-04-05 20:29:56
【问题描述】:

我正在尝试将libjingle_peerconnection 框架导入我的Xcode 项目,但由于某种原因,我无法在Swift 源文件中导入带有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

【问题讨论】:

  • 是的,我是。如果有帮助的话,libjingle_peerconnection 就是 Objective-C。
  • 我没有;我不得不放下它,现在工作忙得不可开交。我会回到它当我可以。可能会退回到 Objective-C。

标签: ios objective-c swift2 cocoapods libjingle


【解决方案1】:

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)

另一个例子是here


► 在GitHub 上查找此解决方案,在Swift Recipes 上查找更多详细信息。

【讨论】:

  • 但正确的方法是在 swift 文件中导入 pod 的模块名称(import xxxx),而不必创建桥接头,只要 pod 文件启用了 use_frameworks,我相信那里libjingle_peerconnection pod 有问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 2016-03-06
  • 2015-10-23
相关资源
最近更新 更多