一: 創(chuàng)建pod項目工程文件
pod lib create ConsultantBase ##ConsultantBase 你要創(chuàng)建的pod名字
之后生成的文件目錄結構是這樣的
我們需要需要將replaceMe替換為我們自己的文件墅诡,效果圖如下:
然后進入Example文件夾執(zhí)行pod update命令李丰,再打開項目工程可以看到,剛剛添加的組件已經在Pods子工程下Development ConsultantBase/ConsultantBase中了。
二: 修改ConsultantBase.podspec文件寨昙,和遠程的鏈接關聯
```
Pod::Spec.new do |s|
s.name = 'ConsultantBase'
s.version = '0.1.0'
s.summary = 'ConsultantBase.'
s.description = <<-DESC
Add long description of the pod here.
DESC
s.homepage = 'https://coding.net/u/Mikes/p/ConsultantSpecs'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Kenvin' => 'yaoyj@oriental-finance.com' }
s.source = { :git => 'https://git.coding.net/Mikes/ConsultantBase.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'ConsultantBase/Classes/**/*'
# s.resource_bundles = {
# 'ConsultantBase' => ['ConsultantBase/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
```
二: 本地庫和遠程關聯
在遠端添加遠端倉庫
git add .
git commit -m "Initial ConsultantBase "
#添加遠端倉庫
git remote add origin https://git.coding.net/Mikes/xxxx.git
#推送到遠端倉庫
git push origin master
對本地庫添加tag標簽
git tag 0.1.0
git push --tag
之后對本地庫進行校驗
pod spec lint --allow-warnings
如果成功,返回:
-> ConsultantBase (0.1.0)
- WARN | [iOS] xcodebuild: ConsultantBase/ConsultantBase/Classes/Category/UITextView+SMKLimitTips.m:153:73: warning: values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat]
Analyzed 1 podspec.
ConsultantBase.podspec passed validation.
如果失敗
~:ConsultantBase Kenvin$ pod lib lint
-> ConsultantBase (0.1.0)
- WARN | [iOS] xcodebuild: /Users/Kenvin/remoteLib/ConsultantBase/ConsultantBase/Classes/Category/UITextView+SMKLimitTips.m:153:73: warning: values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat]
[!] ConsultantBase did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
You can use the `--no-clean` option to inspect any issue.
解決方案是:
~:ConsultantBase Kenvin$ echo "2.3" > .swift-version
三: 將pod組建和自己建立的pod索引庫 xxSpecs 關聯
pod repo add ConsultantSpecs https://git.coding.net/Mikes/xxxxSpecs.git
執(zhí)行:
pod repo
結果:
artsy
- Type: git (master)
- URL: https://github.com/Artsy/Specs.git
- Path: /Users/Kenvin/.cocoapods/repos/artsy
ConsultantSpecs
- Type: git (master)
- URL: https://git.coding.net/Mikes/ConsultantSpecs.git
- Path: /Users/Kenvin/.cocoapods/repos/ConsultantSpecs
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/Kenvin/.cocoapods/repos/master
3 repos
四:向Spec Repo提交podspec文件
pod repo push ConsultantSpecs ConsultantBase.podspec
結果:
五:使用制作好的Pod
在正式項目的Podfile 里添加私有Spec Repo
source 'https://git.coding.net/Mikes/ConsultantSpecs.git'
pod 'ConsultantBase', '~> 0.1.0'
然后執(zhí)行pod update肖爵,更新庫依賴,然后打開項目可以看到臀脏,我們自己的庫文件已經出現在Pods子項目中的Pods子目錄下了劝堪,而不再是Development Pods。