简单理解CocoaPods

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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 项目组件化、平台化是技术公司的共同目标,越来越多的技术公司推崇使用pod管理第三方库以及私有组件,一方面使项目架构...
    swu_luo阅读 22,148评论 0 39
  • Ruby 安装 要安装cocospods 首先需要安装ruby,可以先安装xcode,再安装macport ,最后...
    山天大畜阅读 1,885评论 0 1
  • CocoaPods 是什么? CocoaPods 是一个负责管理 iOS 项目中第三方开源库的工具。CocoaPo...
    朝洋阅读 25,739评论 3 51
  • CocoaPods操作手册 本文档介绍了啥? 为什么要使用CocoaPods? 如何安装CocoaPods? Po...
    风小钻阅读 7,619评论 1 10
  • 这几天整理思绪,把那些犹犹豫豫处理的关系,决定好好区分出来。 人活着,总归得先自己过了自己心里的那一关。不论哪一种...
    漫漫无忧阅读 243评论 5 3