试着做了下 自己在 Cocoapods 封装代码,下面是记录
- 1. 在
github
上创建代码仓库,选择忽略文件和licence
为MIT
- 2. 代码仓库里面 新建
release
注意version
,创建.podspace
文件用到 - 3.
git clone https://www.github.com/xxx/xxx..
把远程仓库clone
到本地 - 4. 把要打包的代码拖到文件夹下,
.xcodeproj
文件要和.git
同一级目录 - 5.
git add -a
把代码从缓存区加到本地仓库 - 6.
git commit -m '描述'
- 7.
git push origin
推到远程仓库的origin
分支(我是直接推到origin
分支的) - 7.1
git tag 1.0.0
(如果远程没有创建release
的话 可以通过7.1方式创建) - 7.2
git push origin --tags
- 8.
pod spec create XXXXX
创建.podspace
文件模板 名字和工程一致 - 9. 打开
XXXXX.podspace
文件 修改
spec.name = "项目名字"
spec.version = "1.0.0" (和仓库 tag 相同)
spec.description = <<-DESC
this is cocoapods test (分三行,内容写中间)
DESC
spec.homepage = "[https://github.com/XXXX/(https://github.com/XXXX/)
XlXLog.git"(远程仓库地址)
spec.license = "MIT" (自动生成)
spec.author = { "DoflaKaiGo" =>"[XXXXX@163.com](mailto:XXXX@163.com)" }
spec.source = { :git => "远程地址", :tag=>spec.version }
spec.source_files = "ChainList" 文件夹名称
- 10.
pod trunk register
邮箱 昵称--description
=“描述” 注册trunk
账号 - 11. 进入邮箱,打开链接,完成验证,回到终端
- 12.
pod trunk me
验证是否激活成功 - 13.
pod spec lint xxxxx.podspec
检查.podspec
文件是否合法,若果有error
根据报错提示修改 - 13.1
pod lib lint xxxxx.podspec
检查文件,功能同上,没有详细的报错log
,只有有没有通过 - 14.
pod lib lint --allow--warnings
如果有warning
的时候可以选择忽略错误 - 15.
pod trunk push
推到cocoapods
- 16. 注意 如果前面忽略了警告,推的时候需要使用
pod trunk push xxx.podspace --allow--warning
- 17. 成功之后 重新打开终端就可以在 使用
pod search xxx
找到了
合理使用
cocoapods
封装framework
功能组件能有效减少代码耦合