組件化和私有pod源倉庫

關(guān)于組件化,推薦Casa Taloyum的這篇文章,個人也覺得用runtime來實(shí)現(xiàn)組件化編程才是最apple的方式,這篇文章寫的通俗易懂,內(nèi)容很詳細(xì),感謝Casa Taloyum的這幾篇架構(gòu)的文章??。

以該片文章內(nèi)容為前提,記錄下私有pod源倉庫的創(chuàng)建過程。(示例demo

1.在github上new 一個 repository作為我們的私有Pod源倉庫。然后分別new三個repository作為我們的組件部分:A, A_Category & B_Category.

2.執(zhí)行一下命令,將該倉庫添加到本地。

pod repo add [私有Pod源倉庫名字] [私有Pod源的repo地址]

3.當(dāng)在本地把A, A_Category, B_Category等組件做好之后,要先把他們push到gitHub并打一個tag,以B_Category為例:

git add .
git commit -m "0.0.1"
git push
git tag 0.0.1
git push origin master --tags

tag打完之后,先驗(yàn)證一下我們的podspec文件是否正確,B_Category的podspec內(nèi)容如下

Pod::Spec.new do |s|
  s.name         = "B_Category"
  s.version      = "0.0.1" //這里要和上面的tag對應(yīng)。
  s.summary      = "A short description of B_Category."
  s.description  = <<-DESC
            A short description of B_Category.
                   DESC
  s.homepage     = "https://github.com/LFModulizationDemo/B_Category"
  s.license      = "MIT"
  s.author       = { "archerLj" => "lj0011977@163.com" }
  s.platform     = :ios, "7.0"
  s.ios.deployment_target = "7.0"
  s.source       = { :git => "https://github.com/LFModulizationDemo/B_Category.git", :tag => "#{s.version}" }
  s.source_files = "B_Category/B_Category/**/*.{h,m}"
  s.requires_arc = true
  s.dependency "CTMediator"
end

創(chuàng)建podspec文件的命令

pod spec create B_Category

執(zhí)行下列命令驗(yàn)證podspec正確性:

pod spec lint B_Category.podspec --verbose --allow-warnings

驗(yàn)證通過之后,將其push到我們的私有Pod源倉庫中去即可

pod repo push PrivateRepo B_Category.podspec --verbose --allow-warnings

如果本身組件還依賴其他的私有pod源中的組件,以A模塊為例,它不但依賴CTMediator, 還依賴B_Category, 其中B_Category是我們的私有Pod源中的一個組件,這時候驗(yàn)證podspec文件就要指定B_Category組件的位置。

pod spec lint --sources='PrivateRepo,master'  A.podspec --verbose --allow-warnings

這里sources中指定私有Pod源的名字,不要使用url,通過下列命令查看名字即可:

pod repo list

4. 將三個組件全部push到私有源之后,在主工程的Podfile文件中添加他們即可:

source 'https://github.com/LFModulizationDemo/PrivateRepo.git'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

target 'MainProject' do
  pod 'A'
  pod 'A_Category'
  pod 'B_Category'
  pod 'HandyFrame'
end

這里需要指定我們私有源的位置https://github.com/LFModulizationDemo/PrivateRepo.git, 一旦指定了私有源,就一定要把官方的也帶上。
執(zhí)行pod install去玩即可。


最后幫朋友打個小廣告

一個有趣的迷你小程序

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容