在原始沒有三方管理的時代,使用大牛寫好的三方框架狞膘,我們都是采用直接將人家寫好的框架直接拖進來使用滔迈,我們會發(fā)現(xiàn)止吁,如果該三方的版本進行了升級,那豈不是又要去github下載下來燎悍,然后再去工程目錄里面去替換敬惦,不僅增加了工作量,而且還使得項目文件目錄非常不雅觀谈山,于是cocoapods應(yīng)運而生俄删,有了cocoadpods這個專門管理三方的工具,我們會發(fā)現(xiàn)管理三方變得如此簡單勾哩。
首先是cocoapods的安裝:
Last login: Tue May 14 20:55:59 on ttys000
xiongdeMacBook-Pro:~ xiongchen$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Enumerating objects: 290, done.
remote: Counting objects: 100% (290/290), done.
remote: Compressing objects: 100% (223/223), done.
remote: Total 3141156 (delta 112), reused 155 (delta 58), pack-reused 3140866
Receiving objects: 100% (3141156/3141156), 648.56 MiB | 3.86 MiB/s, done.
Resolving deltas: 100% (1872151/1872151), done.
Checking out files: 100% (328598/328598), done.
CocoaPods 1.7.0.rc.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.7.0.rc.1
Setup completed
xiongdeMacBook-Pro:~ xiongchen$ pod --version
1.6.1
xiongdeMacBook-Pro:~ xiongchen$ gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
xiongdeMacBook-Pro:~ xiongchen$
看上面的代碼:
首先我們檢查鏡像源:
gem sources -l
如果沒有source的時候抗蠢,我們需要添加一個源:
gem sources -a https://ruby.taobao.org
這里使用的不是淘寶的鏡像源,開發(fā)者也可以使用淘寶的源;
然后開始安裝cocoapods:
使用命令:
sudo gem install cocoapods
然后初始化三方庫索引:
pod setup
這里的下載有點慢,請完成至100%思劳,完成之后可以檢查cocoadpods的版本號:
pod --version
如果有版本號的話迅矛,恭喜你,cocoapods已經(jīng)安裝成功了潜叛!
可以在命令行里面嘗試搜索下某個三方:
pod search 'SDWebImage'
如果出現(xiàn)一些關(guān)于SDWebImage的三方庫的話秽褒,cocoapods就可以開始正常使用了!
接下來就是cocoapods的基本使用威兜,大致命令如下:
首先cd到工程根目錄下:
然后新建一個podfile,這個podfile主要用于編輯三方需要的一些三方庫名稱和版本信息:
Last login: Wed May 15 08:58:32 on ttys000
xiongdeMacBook-Pro:~ xiongchen$ cd /Users/xiongchen/Desktop/DriveJouyney
xiongdeMacBook-Pro:DriveJouyney xiongchen$ vim podfile
platform :ios,'8.0'
target 'DriveJouyney' do
pod 'AFNetworking'
pod 'MJRefresh','~>1.4.7'
end
退出完成之后進行安裝 pod install命令:
Last login: Wed May 15 08:58:32 on ttys000
xiongdeMacBook-Pro:~ xiongchen$ cd /Users/xiongchen/Desktop/DriveJouyney
xiongdeMacBook-Pro:DriveJouyney xiongchen$ vim podfile
xiongdeMacBook-Pro:DriveJouyney xiongchen$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.2.1)
Installing MJRefresh (1.4.7)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `DriveJouyney.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
xiongdeMacBook-Pro:DriveJouyney xiongchen$
再去工程目錄下销斟,你會發(fā)現(xiàn)有了一個.workspace后綴的文件,以后都直接打開這個文件就可以,如果下次要移除或者增加三方庫椒舵,直接 編輯podfile文件蚂踊,然后cd到該工程目錄下,敲pod install命令笔宿,等待安裝成功即可犁钟。