pod 使用總結(jié)
Cocoapods工具的安裝
Cocoapods安裝方式有兩種,可以直接通過 官網(wǎng) 下載.app 進行安裝,但是個人比較喜歡命令行安裝(需要依賴ruby環(huán)境,Mac 都已經(jīng)搭建好,不需要關(guān)心)
安裝步驟
// 刪除原有的鏡像源
$ gem sources --remove https://rubygems.org/
// 添加國內(nèi)最新的鏡像源(因為之前淘寶的那個好像不更新了)
$ gem source -a https://gems.ruby-china.org/
// 接著執(zhí)行
$ gem sources -l
// 如果出現(xiàn)
> *** CURRENT SOURCES ***
>
> https://gems.ruby-china.org/
// 說明成功了,現(xiàn)在再來執(zhí)行安裝即可
$ sudo gem install cocoapods
注意:OS X 10.11升級,雖然官方聲稱只是一個小小的升級,但是開發(fā)者就需要重新安裝,如果只是按照上述的步驟會出錯
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
但是,別著急,我們有辦法解決,推薦一種常用的解決方法
sudo gem install -n /usr/local/bin cocoapods
pod setup
這個可能會需要一點時間,會輸出Setting up CocoaPods master repo,但是會等待比較久的時間。這步其實是 Cocoapods 在將它的信息下載到 ~/.cocoapods目錄下,如果你等太久,可以試著 cd 到那個目錄,用du -sh *來查看下載進度。
然后你會看到 setup completed
使用方法
創(chuàng)建一個工程
cd 到你的工程,并執(zhí)行 pod init
然后編輯 vi Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'UICollectionViewLayout-Demo' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for UICollectionViewLayout-Demo
pod 'SnapKit'
pod 'Swift-X'
target 'UICollectionViewLayout-DemoTests' do
inherit! :search_paths
# Pods for testing
end
target 'UICollectionViewLayout-DemoUITests' do
inherit! :search_paths
# Pods for testing
end
end
- 最后執(zhí)行 pod install 就完成了。