傻瓜式教學(xué)(記錄)創(chuàng)建Swift的cocoapod私有庫(組件化)
一、簡介
為什么要做這個組件化呢?我個人理解的是,維護(hù)一個組件庫,自由定制的同時避免重復(fù)開發(fā),這個也算工作過程中的成果吧。
二、環(huán)境
Xcode 13.3.1
cocoapod 1.11.3
三、準(zhǔn)備工作
準(zhǔn)備遠(yuǎn)程代碼倉庫比如GIT官網(wǎng)
創(chuàng)建兩個代碼倉庫
1.TestLib用于存放組件源碼
地址:https://github.com/willZTK/TestLib.git
2.TestSpecs用于存放pod索引.podspec文件
地址:https://github.com/willZTK/TestSpecs.git
四、開始
1.在首頁新建文件夾:Modules,終端cd到目錄下,執(zhí)行命令
pod lib create TestLib
TestLib是你的組件名稱
結(jié)果:
截屏2022-05-11 14.32.31.png

截屏2022-05-11 14.39.30.png
用上面的TestLib的地址替換s.homepage、s.source的url,如下:

截屏2022-05-11 15.32.03.png

截屏2022-05-11 14.34.47.png
刪除ReplaceMe.swift文件

截屏2022-05-11 17.01.22.png
4.cd到Example目錄下執(zhí)行命令:
pod install
組件源碼就被導(dǎo)入到Development Pods目錄下了:
截屏2022-05-11 17.03.38.png
到這一步組件源碼配置完成了。
五、上傳組件源碼
返回TestLib目錄
執(zhí)行GIT操作命令:
find . -name ".git" | xargs rm -Rf //清除git
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/willZTK/TestLib.git
git push -u origin main
打tag:
git tag 0.1.0
git push origin 0.1.0
需要注意的是tag版本號0.1.0和TestLib.podspec文件中的version一定要保持一致。
截屏2022-05-11 17.14.59.png
六、創(chuàng)建本地Spec Repo,并上傳索引文件到遠(yuǎn)程倉庫
1.創(chuàng)建本地Spec Repo
執(zhí)行命令:
pod repo add TestSpecs https://github.com/willZTK/TestSpecs.git
然后在 ~/.cocoapods/repos 目錄下就可以看到
截屏2022-05-11 17.24.36.png
2.校驗索引文件.podspecs
返回到TestLib目錄下,執(zhí)行命令:
pod lib lint TestLib.podspec --allow-warnings
得到結(jié)果:
截屏2022-05-11 17.31.34.png
推送索引文件,執(zhí)行命令:
pod repo push TestSpecs TestLib.podspec --allow-warnings
得到結(jié)果:
截屏2022-05-12 14.40.47.png
成功!
七、使用
注意source

截屏2022-05-12 14.44.43.png