CocoaPod 简介

一. pod install vs. pod update

很多人刚接触cocoaPods时,认为pod install只有在第一次设置的时候使用,其实不然。

pod install

安装一个新的pod组件,即使你已经有了Podfile或者以前已经使用过pod install,只要你增加或者删除一个pod库,都要使用pod install

  • 每次使用pod install命令,pod都会重写Podfile.lock里面的版本号
  • 当您运行 pod install 时,它只会解析尚未在 Podfile.lock 中列出的 pod 的依赖项。
  • 对于 Podfile.lock 中列出的 pod,它会下载 Podfile.lock 中列出的显式版本,而不会尝试检查是否有更新的版本可用
  • 对于尚未在 Podfile.lock 中列出的 pod,它会搜索与 Podfile 中描述的内容相匹配的版本(如 pod 'MyPod', '~>1.2')

pod update

想要更新一个pod组件的版本,才会使用这个命令

  • 当你运行pod update PodName(例如AFNetworking),pod将为这个库找到一个最新的, 而不考虑Podfile.lock里面的版本。(只要它符合 Podfile 中的版本限制)
  • 当你使用pod update不加具体的库名称,CocoaPods 会将您的 Podfile 中列出的每个 pod 更新为可能的最新版本。

二.Podfile.lock是什么

Podfile.lock是用来锁定每个pod库的版本号的。

  • 为什么需要podfile.lock,在Podfile里面指定版本不就好了吗?例如pod 'A', '1.0.0'
    举个例子:A库依赖了B库,dependency 'B', '~> 3.0', 不同的人在不同的时间使用pod install,因为依赖的B只要大于3.0即可,所以有的人获取的B是3.0,有的人获取的B是3.5,会导致代码依赖不一样。
    总结:就是Podfile里面并不包含依赖的库,所以需要Podfile.lock来管理所有的库的版本以及依赖的库的版本

三.pod outdated

当您运行 pod outdated 时,CocoaPods 将列出所有版本比 Podfile.lock 中列出的版本更新的 pod(当前为每个 pod 安装的版本)。 这意味着,如果您在这些 Pod 上运行 pod update PODNAME,它们将被更新——只要新版本仍然符合 Podfile 中设置的 pod 'MyPod'、'~>x.y' 等限制。

四.Podfile

  • 看看神奇的optimistic operator 波浪形箭头
    '~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher
    '~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher
    '~> 0' Version 0 and the versions up to 1.0, not including 1.0 and higher
  • Using the files from a folder local to the machine
    pod 'Alamofire', :path => '~/Documents/Alamofire'
    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'
    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'
    pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'
  • 参考demo
  • Non-trivial Podfile in Artsy/Eigen
  • Podfile for a Swift project in Artsy/Eidolon

Question

  • 为什么不使用git subModules
    git subModules也可以用来实现组件化,但是git subMoudels主要是用来管理代码的。而pod不仅实现了代码管理的功能(本地path),同时完成了库的依赖解析,库的版本管理,以及将库自动集成到xcode的功能。
    所以说,pod包含了git subModules的功能,更完善和强大。
  • Testing with CocoaPods 这个还不知道咋用
    Test Specifications
    As of CocoaPods 1.3.0 pods may now provide test specifications (or test specs for short). Test specifications can be used to describe the test sources for a given pod.

Tips

  • 苹果官方出品了一个spm,未来可能取代Pod
  • If you want multiple targets to share the same pods, use an abstract_target.
  • 官方问题解决方案 https://guides.cocoapods.org/using/troubleshooting.html

你可能感兴趣的:(CocoaPod 简介)