组件化的优缺点

组件化的拆分

组件与组件之间如何进行通讯(路由)

从Cocopods拉取代码的过程

远程索引库里很多的.spec文件,该文件记录了很多内容,如用户名,框架名称,描述,框架的地址
Podfile 文件是拉取框架源码的配置文件, pod install 命令会根据Podfile中配置来拉取框架源码
Pod setup 命令会把远程索引库拷贝到本地,在本地还有一个检索文件
执行pod search命令过程,并不是直接从远程索引库查找,它是从本地的检索文件,该检索文件是以键值对的形式存在。在本地索引库中会找到对应的.spec文件 , .spec文件中有框架源码的地址,直接从这个地址来下载了。
Pod repo 命令可以查看本地的索引库列表
创建本地私有库

Pod lib create 命令是创建lib库的模板

更正:创建demo的位置,应该选择YES
创建成功后的目录结构如下:

接下来,我们可以把拆分的代码放到如下这个目录下:

放入代码后的目录结构如下:

Xcode中的工程并不会显示新加入的文件,如下图所示:

我们只需要在命令行工具中 cd 到Pods 工程所在的文件夹,执行pod install 命令即可

命令执行完成后,我们添加到目录中的代码文件已经被加入到工程中,此时目录结构如下:

如果工程中的代码依赖了别的第三方库,我们还需要在.podspec文件中加入框架依赖

配置好.podspec 库后,回到Example目录, 在此目录下执行 pod install 来安装工程依赖的三方框架
在其他工程中使用本地私有库时,要注意本地私有库引入的位置

本地私有库上传到远程私有库
在码云gitee.com 上创建一个远程私有库

选择私有,并点击导入已有项目,点击创建

根据已有仓库的操作指引,在命令行工具中,cd到lib库所在在目录,执行如下命令


实际新加入的文件还没有提交,我们使用git status看下版本控制的状态(红色部分),然后使用 git add .将文件加入到版本控制中. 使用git commit -m 命令提交到本地, 再使用 git push origin master 提交到远程仓库。



私有库的podSpec配置


需要给当前的lib 库打个tag版本号, 并推送到远程

git tag 命令可以查看当前打的所有的tag, git tag + 版本号 可添加新的tag 提交tag 使用 git push —tags

可以看到远程库上已经打上了一个0.1.0的tag标签,这时我们可以使用 pod spec lint 命令验证配置的正确性
创建远程索引库
同创建远程私有库
将远程索引库关联到本地
- pod repo add RZSpec https://gitee.com/reyzhang/RZSpec.git
复制代码 将RZTools.podSpec提交到这个索引库
- pod repo push RZSpec RZTools.podspec --verbose --use-libraries --allow-warnings
复制代码 使用pod package打包framework 实现组件的二进制化
文章详见: 使用pod package打包framework 实现组件的二进制化
来源:https://www.cnblogs.com/reyzhang/p/16198272.html
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |