如何将Cocoapods与Swift项目集成? [英] How to integrate Cocoapods with a Swift project?
本文介绍了如何将Cocoapods与Swift项目集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
随着Apple推出
As Apple introduced Swift, their new programming language, I wonder how you can integrate it with existing Objective-C libraries that are available via CocoaPods?
解决方案
It seems that the process is similar to the one described in Mix and Match section of Using Swift with Cocoa and Objective-C documentation.
- Create your Podfile and run
pod install
. - Create a new Objective-C header file,
Example-Bridging-Header.h
, and add it to the project. - Add import statement to the bridge header.
- Set
Objective-C Bridging Header
for your target:
Now you can use your library, in that case, MKUnits, in your Swift file:
let kilograms = NSNumber.mass_kilogram(2)()
let pounds = NSNumber.mass_pound(10)()
let result = kilograms.add(pounds)
println(result)
More here: Integrating Cocoapods with a Swift project
这篇关于如何将Cocoapods与Swift项目集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文