Cocoapods 是iOS 開發(fā)中最常用的三方依賴工具鹿鳖,他可以幫我們快速的安裝和管理我們開發(fā)中需要的三方庫粱锐。
第一步樱蛤,安裝Cocoapods
$ sudo gem install cocoapods
第二步钮呀,創(chuàng)建依賴文件
$ cd (your project folder)
$ touch Podfile
第三步,添加需要依賴的三方庫
platform :ios, '8.0'
inhibit_all_warnings! 忽略所有三方庫的警告
use_frameworks! #使用swift時(shí) 必須添加此行
target 'MyApp' do
pod 'IQKeyboardManagerSwift', '~> 3.3.4', :inhibit_warnings => true
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.3.1'
end
tips:
# :path => '~/code/Pods/' 指向本地文件夾 用作開發(fā)# :inhibit_warnings => true 可以忽略掉三方庫中的警告
# :git => 'https://github.com/Alamofire/Alamofire.git' 指向三方庫的git 路徑昨凡,一般用于私有庫
# :branch => 'assets' 指定三方庫的對應(yīng)分支
# :tag => '3.3.1' 指定三方庫的版本對應(yīng)tag
# :commit => 'd45df72' 指定三方庫的commit 版本號
第四步爽醋,執(zhí)行安裝命令
pod install
最后,打開新生成的Project.xcworkspace便脊,開始coding蚂四。
import Alamofire
小記:
- 追加 --verbose 可以顯示debug 信息
- 追加 --no-repo-update 忽略更新
- 使用 pod update 更新已經(jīng)安裝的三方庫
- 在使用版本管理工具時(shí),記得上傳 Podfile.lock 用于管理三方庫版本
- ruby 默認(rèn)源在國內(nèi)訪問較慢哪痰,建議改為國內(nèi)源
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://gems.ruby-china.org
$ gem sources -l
顯示如下更改鏡像成功遂赠!
gem-sources-list.png