最近在學(xué)習(xí)組件化。
組件化有一個方案是利用cocoapods進行管理組件。
這就涉及到了specs私有庫的創(chuàng)建赘阀、維護和使用。
1. 開啟顯示隱藏文件
為了方便查看某些文件是否完成
//打開隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
//關(guān)閉隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false
2. 創(chuàng)建遠程組件索引庫
該庫包含了所有組件的索引以及版本信息脑奠。
命名最好以Specs結(jié)尾,我采用了coding的免費私有庫胰伍。
3. 創(chuàng)建本地組件索引庫
終端輸入:pod repo add REPO_NAME SOURCE_URL
REPO_NAME:倉庫名字,最好和遠程索引倉庫保持一致渗饮,
SOURCE_URL:為倉庫地址特占。
回車后是目,F(xiàn)inder利用~/.cocoapods/repo查看懊纳,可以看到系統(tǒng)已經(jīng)為我們創(chuàng)建好了文件夾和基本配置嗤疯。
4. 創(chuàng)建 lib
4.1創(chuàng)建遠程代碼庫
4.2 本地創(chuàng)建項目,將庫文件引入工程, 關(guān)聯(lián)遠端的庫.
終端輸入:pod lib create REPO_NAME
4.3 將庫文件引入工程,
完成后,將你的代碼庫代替Classes里的ReplaceMe.m
終端進入Example文件夾
pod install
可以看到項目中已經(jīng)導(dǎo)入添加在Classes里的代碼
4.4 將本地 lib 關(guān)聯(lián)到遠端庫
git add .
git commit -m "first commit"
git remote add origin SOURCE_URL
git tag '0.0.1'
git push --tags
git push -f origin master
5. 配置 podspec 文件
5.1 修改.podspec文件
#
# Be sure to run `pod lib lint basedModule.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = '組件名字'
s.version = '組件版本'
s.summary = '組件描述'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
組件詳細描述
DESC
s.homepage = '組件代碼主頁'
# s.screenshots = '組件代碼庫地址'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '作者' => '作者地址' }
s.source = { :git => '組件代碼庫地址', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '最低版本'
s.source_files = '組件名字/Classes/**/*'
# s.resource_bundles = {
# '組件名字' => ['組件名字/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
5.2 檢測spec是否可用
pod lib lint --allow-warnings
pod spec lint --allow-warnings
--allow-warnings
:忽略所有警告,并通過校驗缓艳。
--no-clean
:檢查任何問題郎任。
--verbose
:查看詳細的驗證過程來幫助定位錯誤
--use-libraries
:通過含有.a靜態(tài)庫的驗證
5.3 提交 podspec 至私有 Spec 倉庫
在 podspec 文件目錄執(zhí)行
pod repo push REPO_NAME MODULE_NAME.podspec --allow-warnings
6.更新 Pod
如果在開發(fā)過程中發(fā)現(xiàn)某基礎(chǔ)組件存在 bug 需要更新 Pod分井,具體操作步驟如下:
修改 podspec 文件中的 s.version;
修復(fù) bug 并對項目打 tag,tag 名稱和 s.version 一直并 push 到遠程倉庫瘫辩。
驗證 podspec 文件的有效性伐厌;
推送 podspec 文件到遠程倉庫挣轨;
執(zhí)行 pod search RRCache 驗證結(jié)果卷扮;
創(chuàng)建時會遇到的一些問題
- 查找有無
ERROR
晤锹,有的話,修復(fù)相應(yīng)的BUG - 沒有
ERROR
车遂,但是有很多WARN
艰额,很多WARN
無法
解決的柄沮,加上--allow-warnings
可以解決 - 如果有靜態(tài)庫或者是framework祖搓,加上
--use-libraries