# CocoaPods庫制作
## CocoaPods原理:
1. 索引庫(specs repo),庫內維護所有組件的podspec文件。
2. 組件代碼庫,庫內維護組件代碼,podspec配置源碼git地址,podspec文件與索引庫內的同步
3. 通過pod命令在索引庫內查找到對應組件的podspec文件,通過該文件找到對應的組件代碼庫位置,然后進行同步
4. 自制公有組件,即將自己的組件代碼庫podspec提交到CocoaPods的索引庫: https://github.com/CocoaPods/Specs.git
5. 自制私有組件,即自建一個索引庫,然后將代碼庫podspec提交到自建索引庫
## 一、spec索引庫制作
1. git服務器上建索引庫,如:TestSpecs.git
2. 本地創建索引庫并連接git服務端:pod repo add TestSpecs https://.../TestSpecs.git
3. pod repo list 查看
4. 本地索引庫位置:~/.cocoapods/repos. 在TestSpecs內新增README.md文件初始化,避免后期同步索引庫時報錯
5. pod repo remove REPO_NAME
6. pod repo update
## 二、組件代碼庫制作
1. pod lib create TestKit,自動創建組件項目,自帶Classes, Example
2. pod spec cretae TestKit,手動創建組件spec文件,需要自己創建項目然后配置該podspec文件
3. git服務器上創建代碼庫,如:TestKit.git
4. 開發代碼,提交到TestKit.git。完成開發后打Tag(git tag 0.0.1, git push --tags),編輯podspec內組件版本
5. pod spec lint 檢查podspec
## 三、提交組件podspec 到 spec索引庫
1. pod repo push [spec索引庫名] [組件podspec]
2. pod search TestKit, 檢查是否成功
## 四、Podfile內使用
Podfile頂部添加自己私有索引庫的地址:source 'https://.../TestSpecs.git'