使用Pod可以方便的给程序添加一些开源库,使开发更有效率。
在自己所建立的ios的swift工程文件目录下,执行如下。
CocoaPods 版本升级
$ sudo gem install cocoapods --pre
$ pod --version
0.36.0.beta.2
生成 Podfile
$ pod init
$ vi Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'XXXXX' do
end
target 'XXXXXTests' do
end
在Podfile中添加要导入的库
pod 'Alamofire'
pod 'SwiftyJSON'
pod 'Alamofire-SwiftyJSON', :git => "https://github.com/SwiftyJSON/Alamofire-SwiftyJSON.git"
安装
pod install
这个时候会在工程文件同一级生成一个Workspace文件,双击workspace文件,就可以打开自己的工程和添加的库了。
维护
今后需要添加或删除一些开源库时,需要关掉Xcode。
然后修改Podfile,然后执行install就可以了。
非常的方便
遇到的错误1
[!] Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add `use_frameworks!` to your Podfile or target to opt into using it
在podfile文件里添加
use_frameworks!
错误2
执行install后,长时间没有反应。
$ pod install
Updating local specs repositories
将Local的
$ pod repo remove master
Removing spec repo `master`
$ pod setup
Setting up CocoaPods master repo
Setup completed
$ pod install
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
(中略)
Generating Pods project
Integrating client project
Sending stats
参照:
http://d.akiroom.com/2015-08/pod-install-forever/
http://qiita.com/yokomotod/items/884f624cf17ba4a5ef11