最近不是很忙,所以学习了下cocoapods私有库的创建。一直都想学习组件化,现在就从创建私有库开始。下面简单做下记录,一边以后学习!!!
1.创建远程索引库
远程仓库可以在码云、github等地方进行创建,这里我就用github进行创建。
1)打开https://github.com

2.创建本地索引库
1)查看本地索引库
在终端输入命令 pod repo

2)添加本地索引库
在终端输入命令 pod repo add 索引库名称 远程索引库地址, 比如pod repo add test https://github.com/xxx/test.git;通过pod repo 查看新创建的库是否成功,或者在文件夹/.cocoapods/repos/中查看;此时,本地索引库创建完成。
3.创建远程代码库,过程同一,这里就不多说。
4.创建本地代码库
1)创建本地代码组件模版库 终端输入命令 pod lib create <组件名>。组件名可以和远程代码库一致

2)以下就是创建的工程
在Xcode彻底删除ReplaceMe.m文件,接着把自己封装好的组件代码文件拖入到Classes路径下

3)接着cd到Example下进行pod install (把刚才拖入到classes里的文件夹pod进来,这里会通过podfile里面默认的设置,自动把classes里的文件pod过去)
编译组件看是否报错,编译通过后需要修改podspec索引文件,一般需要修改下面几个问题。
首先要修改版本号s.version,然后修改s.source_files = 'MyTools/Classes/*.{h,m}',这两个必须要修改,另外依赖库可根据需要添加。
4)编译运行通过后,提交组件到远程仓库并打tag

5)验证仓库有效性
终端输入命令 pod spec lint --allow-warnings ,这个地方可能会提示找不到source_files,解决办法是s.source 里面添加 :commit => 'fafe56de2d5d3a883f4545699df86ea621845216' (commit后面的是最新提交的那串字符)

6)验证通过后
在终端执行pod repo push <本地索引库> <索引文件名> --allow-warnings, 提交索引文件到远程索引。例如pod repo push MySpec MyTools.podspec,提交成功后。大功告成
网友评论