美文网首页
简单理解CocoaPods

简单理解CocoaPods

作者: Fdom | 来源:发表于2017-07-27 15:04 被阅读8次

CocoaPods

Cocoapods是OS X和iOS下的一个第三方库管理工具。

意义

  1. 简化引入第三方库的配置工作项目中引入第三方库不可避免的要进行各种各样的配置,对于一些OC初级开发者来说,项目配置是一件繁琐且复杂的工作,在配置编译器和链接器选项的过程中很可能引入人为错误,而cocoapods简化了这一过程,它能够自动配置编译选项,方便了开发者。
  2. 可以方便地查找第三方库
    可以找到真正好用的第三方库,提升代码质量。

核心组件

CocoaPods是由ruby写的,并划分成了若干Gem包,在解析执行过程中几个重要的路径分别是CocoaPods/CocoaPods,CocoaPods/Core,CocoaPods/Xcodeproj.

  1. CocoaPods/CocoaPods:面向用户组件,所有的pod命令都在该组件内,它包括了所有实用的CocoaPods的功能,并且还能调用其他gem包来执行任务。

  2. CocoaPods/Core:提供了与CocoaPods相关的文件的处理(主要是podfile、pod specs)

  3. CocoaPods/Xcodeproj:负责与工程文件关系的处理。可以创建、修改.xcworkspace文件。

podfile&&podspec

  1. podfile:用于配置项目需要的第三方库,可以被高度定制,添加你想要的特性,详细使用教程:http://guides.cocoapods.org/syntax/podfile.html

  2. podspec:描述了一个库将怎样被加入到项目中,podspec可以标示该第三方库所需要的源码文件、依赖库、编译选项、库暴露的头文件等。

pod install 和 pod update的区别

pod install(下载并安装pod)

  1. 当pod file文件中有“增加pod,删除pod,修改pod”的操作之后使用。
  2. pod install执行完之后会将已下载的依赖库的版本号添加进podfile.lock文件
  3. pod install根据podfile.lock文件列出的已安装的pod的版本信息,只负责下载安装podfile.lock中不存在的pod,不会自动更新已安装的pod的版本。

pod update (更新已存在的pod)

  1. 按规则将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.

相关文章

网友评论

      本文标题:简单理解CocoaPods

      本文链接:https://www.haomeiwen.com/subject/zcvzkxtx.html