什么是CocoaPods
CocoaPods就是一種依賴管理工具。CocoaPods項目的源碼在Github上管理。該項目開始于2011年8月12日,經過多年發展,現在已經成為iOS開發事實上的依賴管理標準工具。開發iOS項目不可避免地要使用第三方開源庫,CocoaPods的出現使得我們可以節省設置和更新第三方開源庫的時間
目的
網絡上介紹CocoaPods使用方法的帖子已經很多了。寫這篇帖子是因為最近自己使用CocoaPods遇到了一些坑,自己填填,也希望能給別人一個參考
安裝CocoaPods
查詢Ruby的源
gem source -l
查詢結果如下:
*** CURRENT SOURCES ***
這個鏡像在國外,如果直接安裝可能速度可能非常慢
移除Ruby的源
gem source --removehttps://rubygems.org/
移除結果如下:
http://rubygems.org/removed from sources
添加Ruby的源(最近做了修改, 改為了https)
gem source -ahttps://ruby.taobao.org/
添加結果如下:
https://ruby.taobao.org/added to sources
對源的操作完成后, 就可以安裝CocoaPods了
安裝
運行以下命令, 即可實現CocoaPods的安裝
sudo gem install cocoapods
運行之后需要輸入電腦的密碼, 并且沒有密碼輸入的位數提醒。輸完密碼就進行安裝了,安裝過程可能會很慢,耐心等待。
上述命令安裝完成后,輸入以下命令, 進行Cocoapods的建立
pod setup
使用CocoaPods
這里就遇到了坑點
網上的podfile都是這樣寫的
platform :ios
pod 'ReactiveCocoa','~>2.1.8'
執行podinstall就遇到了這樣的問題
Analyzing dependencies
[!] The dependency `ReactiveCocoa (~> 2.1.8)` is not used in any concrete target.
當時折騰了好久,網上說是CocoaPods的版本問題,試了半天,然并卵~
最后在CocoaPods官網找到,podfile要這樣寫了
target ‘racTextOne’ do
pod 'ReactiveCocoa','~>2.1.8'
end
'racTextOne'是我的工程名
執行podinstall,ok
Analyzing dependencies
Downloading dependencies
Installing ReactiveCocoa (2.1.8)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total
pod installed.
參考資料
1.官網地址:https://cocoapods.org