選Github或者碼雲均可以,本例以Github爲例。建立私有索引庫用來做爲本身組件庫的索引:git
添加:pod repo add 索引庫名稱 索引庫地址github
例:pod repo add ZYHModule https://github.com/zyhDeveloper/ZYHModule.gitbash
查詢:pod repo工具
在命令行工具裏cd進入桌面文件夾測試
執行:pod lib create 組件名ui
例:pod lib create XXModulesspa
咱們把基礎組件相關的東西丟到Classes文件夾中,而且把ReplaceMe.m
文件刪除命令行
執行:code
git rm XXModule/Classes/ReplaceMe.morm
git add .
在Example項目的Podfile文件中能夠看到 「 pod 'LXFBase', :path => '../' 」,模板庫已經默認幫咱們在Podfile中指定了LXFBase.podspec的位置,咱們無需操做,直接在命令行工具裏cd到Example文件夾,執行pod install
標籤與spec中的s.version
保持一致
git tag -a 0.1.0 -m "Release version 0.1.0"
git push origin --tags
先作個本地和遠程驗證
pod lib lint --allow-warnings
測試下搜索咱們的組件:pod search XXModules
cd到開發的項目工程文件
執行:pod init
// 第二行是爲了保證公有庫的正常使用
source 'https://github.com/zyhDeveloper/ZYHModule.git'
source 'https://github.com/CocoaPods/Specs.git'
添加:pod 'XXModules'
執行:pod install
組件庫當有新增文件或者發生修改或者刪除時,更新迭代執行:
刪除:git rm XXXX
git add .
git commit -m '更新描述'
git push origin master
版本更新 這一步很是重要,爲更新索引庫作準備
git tag -a 0.2.0 -m "Release version 0.2.0"
git push origin --tags
打開你的xx.podspec
文件,將本來的版本號改成0.2.0
,與剛剛的tag保持一致
git add .
git commit -m '更新描述'
pod spec lint --allow-warnings
// pod repo push 索引庫名稱 xxx.podspec
pod repo push ZYHModule XXModule.podspec --allow-warnings
pod update
若是咱們只須要用到SDWebImage中的GIF功能,那麼並不須要將整個SDWebImage都下載下來,在Podfile中將~~pod 'SDWebImage'
~~ 改成 pod SDWebImage/GIF
便可單獨使用這一功能。
子庫格式
s.subspec '子庫名稱' do |別名|
end
使用說明:
s.source_files = 'XXModule/Classes/*'
# s.dependency 'SDWebImage', '~> 4.3.3'主庫的依賴庫
s.subspec 'Cache' do |c|
c.source_files = 'XXModule/Classes/Manager/**/*'
c.dependency 'SDWebImage', '~> 4.3.3' 子庫的依賴庫
end
s.subspec 'Manager' do |m|
m.source_files = 'XXModule/Classes/Category/**/*'
end
修改後再按以前的步驟更新索引庫和組件庫就能夠了
pod spec lint --allow-warnings(若是文件路徑沒問題,出現The`source_files` pattern did not match any file
可嘗試新設置tag)
pod repo push ZYHModule XXModule.podspec --allow-warnings
pod update
如需在某個工程添加子庫,可執行:
pod 'XXModule/Manager'
pod install
資源文件都放在Assets文件夾中
將關於資源加載的註釋去掉
s.resource_bundles = {
# 'LXFMain' => ['LXFMain/Assets/*.png']
改成:'LXFMain' => ['LXFMain/Assets/*']
}
使用[UIImage imageNamed:@"圖片名稱"]加載不出來圖片
使用如下代碼:
若是是直接在xib中拖入一個imageView控件來設置圖片的加載,咱們則須要在圖片名字前加上當前bundle名稱 XXXX.bundle/圖片名字
本地私有索引庫路徑:/Users/Mr.z/.cocoapods/repos
刪除私有索引庫:
pod repo remove [索引庫名稱] //移除本地索引庫