隨着應用需求逐步迭代,應用的代碼體積將會愈來愈大,爲了更好的管理應用工程,咱們開始藉助CocoaPods版本管理工具對原有應用工程進行拆分。可是僅僅完成代碼拆分還不足以解決業務之間的代碼耦合,爲了更好的讓拆分出去的業務工程可以獨立運行,必須進行組件拆分而且實現組件服務化。git
組件化開發優勢:github
1.組件和組件之間沒有明確的約束。xcode
2.組件單獨開發、單獨測試,不能揉入主項目中開發,測試也能夠針對性的測試。ruby
組件主要分爲三類:工具
基礎功能組件:組件化
基礎 UI 組件:測試
產品業務組件:fetch
使用 CocoaPods 製做私有庫實現過程:spa
一、建立索引庫:code
可以使用 GitHub、Gitlab、Gitee、等,以 GitHub 爲例:
二、將建立的索引庫添加到本地 Cocoapods 倉庫中:
pod repo add UCKit https://github.com/zhangtibin/UCKit.git
路徑是:~/.cocoapods/repos
三、建立模板:
pod lib create UCKit
按提示輸入選擇後,建立完成,會自動打開 Xcode 工程:
在 Classes 目錄下,放入須要添加組件的文件:
進入 Example 目錄下,執行:pod install。
四、**.podspec 文件中更改模板文件相關信息:
五、驗證 .podspec 文件:
pod lib lint UCKit.podspec --allow-warning
六、將製做好的組件上傳至 GitHub
git remote add origin https://github.com/zhangtibin/UCKit.git
git push -u origin master
若是出現報錯時,以下,能夠採用修改衝突文件,並提交至 GitHub
提交完以後
七、使用:
pod 'UCKit' , :git =>'https://github.com/zhangtibin/UCKit.git'
在執行:pod lib lint UCKit.podspec --allow-warning
出現錯誤:- ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices
xcode設置裏面,將Command line Tools設置一下,在Xcode>preferences>Locations裏面,設置以後再運行終端便可。
解決後,當出現 ** passed validation表示驗證成功:
執行:git push -u origin master
報錯:
! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/zhangtibin/UCKit.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
緣由:遠程repository和我本地的repository衝突致使的,而我在建立版本庫後,在github的版本庫頁面點擊了建立README.md文件的按鈕建立了說明文檔,可是卻沒有pull到本地。這樣就產生了版本衝突的問題。
解決方案:push前先將遠程repository修改pull下來。
$ git pull origin master
$ git push -u origin master
推送以後,就會在 GitHub 上看到新提交的