1.创建一个 Git仓库,这个仓库你可以创建私有的也可以创建公开的,我是创建私有的仓库(http://git.oschina.net)。

填完点击创建

仓库创建完成之后在Terminal中执行如下命令
pod repo add [私有库的名称] [私有库的下载地址]
pod repo add NNSpecs https://git.oschina.net/ffwang/nnspecs.git
在执行之前可看一下~/.cocoapods/repos目录下有些什么
执行之后在会把刚才建立的仓库下载到~/.cocoapods/repos目录

2.创建Pod项目工程文件
如果是有现有的组件项目,并且在Git的版本管理下,那么这一步就算完成了,可以直接进行下一步了
现在从零开始创建一个组件库。
先cd到要创建项目的目录然后执行 pod lib create [库名]
pod lib create FFTestLibrary
执行后会问你四个问题,1.是否需要一个例子工程;2.选择一个测试框架;3.是否基于View测试;4.类的前缀;4个问题的具体介绍可以去看官方文档

都填完执行后会自动打开xcode,先把xcode关一下看看目录结构

打开FFTestLibrary目录可以看到Assets和Classes目录


现在打开FFTestLibrary.podspec文件

这个里面怎么写到处都有,就不多说啦
3.添加远端仓库,同样去GitHub或其他的Git服务提供商那里创建一个私有的仓库
和第一步一样创建一个私有仓库,然后cd到需要放的目录
git clone https://git.oschina.net/XXXX/fftestlibrary.git
把之前创建的FFTestLibrary里面的Example、FFTestLibrary、FFTestLibrary.podspec这3个放到上面cd的目录,然后准备push到仓库去
git add .
git commit -s -m "Initial Commit of Library"
git push origin master #提交到远端仓库
git tag -m "first release" "0.1.0" #添加tag
git push --tags
tag非常重要一定要
tag的值要和FFTestLibrary.podspec 中的s.version一样
看到网上别人push之前执行git remote add origin xxxxxxxx这一条,但是我执行了会报错说已经存在了,所以我就省了

看到这些这是已经提交成功了
4.验证FFTestLibrary.podspec文件是否正确
执行 pod lib lint

再执行 pod spec lint ,一样看到绿字就成功了
不验证直接push也是可以的,只要有信心一定没问题就行
5.向Spec Repo提交podspec
pod repo push NNSpecs FFTestLibrary.podspec #前面是本地Repo名字 后面是podspec名字


现在可以搜一下试试看
pod search FFTestLibrary

可以搜到说明已经加成功了
现在打开xcode建一个新的工程试试看

这样好像没毛病 但是在终端pod install一下发现不好用

这里需要最后一步push到trunk上
pod trunk push FFTestLibrary.podspec

看到这里才算完成了
要删除私有Spec Repo下的某一个podspec
只需要cd到~/.cocoapods/repos/[自己的Specs]目录下,删掉库目录
git add .
git commit -m "删掉库目录了"
git push origin master
打完以上3条命令就完成了
最后聊一下可能遇到的坑
在 pod lib create [XXX库名] 的时候可能会出错

输入上面提示的colored2的两条gem命令即可解决问题
sudo gem install colored2
sudo gem update --system
在最后pod install的时候我们的库会找不到

只需在podfile中加入source即可

加上之后再pod install就能成功了
需要使用自己的私有库和pod官方的库都想用就必须在podfile中添加source
source 'https://github.com/tmd2013/FFWangSpec.git'
source 'https://github.com/CocoaPods/Specs.git'

网友评论