CocoaPods
Cocoapods是OS X和iOS下的一個第三方庫管理工具忧侧。
意義
- 簡化引入第三方庫的配置工作項目中引入第三方庫不可避免的要進行各種各樣的配置罗丰,對于一些OC初級開發(fā)者來說锰什,項目配置是一件繁瑣且復雜的工作忍饰,在配置編譯器和鏈接器選項的過程中很可能引入人為錯誤兵钮,而cocoapods簡化了這一過程胞皱,它能夠自動配置編譯選項,方便了開發(fā)者综芥。
-
可以方便地查找第三方庫
可以找到真正好用的第三方庫丽蝎,提升代碼質量。
核心組件
CocoaPods是由ruby寫的膀藐,并劃分成了若干Gem包屠阻,在解析執(zhí)行過程中幾個重要的路徑分別是CocoaPods/CocoaPods,CocoaPods/Core额各,CocoaPods/Xcodeproj.
CocoaPods/CocoaPods:面向用戶組件国觉,所有的pod命令都在該組件內,它包括了所有實用的CocoaPods的功能虾啦,并且還能調用其他gem包來執(zhí)行任務麻诀。
CocoaPods/Core:提供了與CocoaPods相關的文件的處理(主要是podfile痕寓、pod specs)
CocoaPods/Xcodeproj:負責與工程文件關系的處理∮眨可以創(chuàng)建呻率、修改.xcworkspace文件。
podfile&&podspec
podfile:用于配置項目需要的第三方庫丁眼,可以被高度定制筷凤,添加你想要的特性,詳細使用教程:http://guides.cocoapods.org/syntax/podfile.html
podspec:描述了一個庫將怎樣被加入到項目中苞七,podspec可以標示該第三方庫所需要的源碼文件藐守、依賴庫、編譯選項蹂风、庫暴露的頭文件等卢厂。
pod install 和 pod update的區(qū)別
pod install(下載并安裝pod)
- 當pod file文件中有“增加pod,刪除pod惠啄,修改pod”的操作之后使用慎恒。
- pod install執(zhí)行完之后會將已下載的依賴庫的版本號添加進podfile.lock文件
- pod install根據podfile.lock文件列出的已安裝的pod的版本信息,只負責下載安裝podfile.lock中不存在的pod撵渡,不會自動更新已安裝的pod的版本融柬。
pod update (更新已存在的pod)
- 按規(guī)則將podfile文件中的pod更新到最新版本。并將pod版本信息寫入podfile.lock
原版解釋
pod install
This is to be used the first time you want to retrieve the pods for the project, but also every time you edit your Podfile to add, update or remove a pod.
Every time the pod install command is run — and downloads and install new pods — it writes the version it has installed, for each pods, in the Podfile.lock file. This file keeps track of the installed version of each pod andlocks those versions.
-
When you run pod install, it only resolve dependencies for pods that are not already listed in thePodfile.lock.
- For pods listed in the Podfile.lock, it downloads the explicit version listed in the Podfile.lock without trying to check if a newer version is available
- For pods not listed in the Podfile.lock yet, it searches for the version that matches what is described in the Podfile (like in pod 'MyPod', '~>1.2')
pod outdated
- When you run pod outdated, CocoaPods will list all pods which have newer versions than the ones listed in thePodfile.lock (the versions currently installed for each pod). This means that if you run pod update PODNAME on those pods, they will be updated — as long as the new version still matches the restrictions likepod 'MyPod', '~>x.y' set in your Podfile.
pod update
When you run pod update PODNAME, CocoaPods will try to find an updated version of the pod PODNAME, without taking into account the version listed in Podfile.lock. It will update the pod to the latest version possible (as long as it matches the version restrictions in your Podfile).
If you run pod update with no pod name, CocoaPods will update every pod listed in your Podfile to the latest version possible.