前言
最近一段时间在研究组件化,主要是基于CocoaPods的组件化方案,特此做个笔记,加强自己的记忆吧,大家可以一起探讨组件化中遇到的问题和想法!
CocoaPods最新安装教程:
https://www.jianshu.com/p/f43b5964f582
常见pod命令回顾:
在开始之前,回顾一下组件化中常用的pod命令:
查看本机CocoaPod版本:
pod --version

查看本机CocoaPod源:
pod repo

由上图可以看出我的电脑上有两个源,即master和FDMediaSpecs
添加pod库源:
pod repo add NAME URL [BRANCH]
pod repo add xxx http://xxxxxx.git master
删除pod库源:
pod repo remove 源名字
⚠️源名字即master或者FDMediaSpecs
创建podfile文件:
pod init

然后就是编辑podfile文件podfile文件语法可以参考此文:
podfile语法
安装podfile中的三方库:
pod install
升级podfile中的三方库:
pod update
cocapods本地spec索引库的位置:
/Users/mac/.cocoapods/repos/master/Specs
cocoapods本地spec索引库检索索引文件位置:
/Users/mac/Library/Caches/cocoapods/search_index.json
cocoapods管理三方库原理:
首先撸了一张图大家凑合着看

流程解析
1.cocoapods 在官方在github创建了一个specs仓库用于存储github上可以使用pod管理三方库的podspec文件
三方库的podspec文件如下图:

githubspecs仓库里的文件:

2.每一个需要使用pod管理的三方库都会生成一个podspec文件,然后吧文件上传到cocoapods 在官方在github创建的specs仓库中;
podspec文件内容:

上图可见文件中包含了三方库的作者、版本、地址、代码地址等信息(podspec文件的制作、上传及填写会在以后内容中谈到);
3.用户安装cocoapods时执行
pod setup
时会去github的specs仓库中下载相关的文件到本地方便检索cocapods本地spec索引库的位置:
/Users/mac/.cocoapods/repos/master/Specs

4.用户执行pod search
时会根据本地specs仓库去创建search_index.json的索引文件,索引文件中包含了一个个三方库的podspec文件中的信息
生成索引文件:

search_index.json文件的位置:
/Users/mac/Library/Caches/cocoapods/search_index.json

5.用户在执行pod install
时,pod会从上一部创建的search_index.json索引文件中去检索podfile文件中三方库的地址并去github下载安装;pod update回去更新本地的索引库并重新生成索引文件
安装三方库:

至此,cocoapods的相关流程已经说完了!
网友评论