iOS开发私有库的创建
近期由于自己在玩玩私有库和公有库,记录下来自己搭建的过程。私有库可以本地和远程,这里主要是将远程库的搭建。
当然在开始使用github创建私有库之前需要先配置好github上的SSH keys https://github.com/settings/keys 这个自行去百度。
1、创建远程索引库
基本上每创建一个组建都会带有xx.podspec的文件,专门用来存在这些索引文件的库就是索引库,需要将这些索引文件上传到远程索引库才能与他人共享组件。

2)创建成功之后看到该文件

2、本地索引库
本地索引库就是用来存放本地索引文件的库。
1)打开终端输入
pod repo
即可以查看本地的索引库

2)通过
pod repo add
本地索引库的名字 远程索引库的地址
如pod repo add test https://github.com/xxxx/test.git,创建本地索引库和远程索引库做关联
由于我之前已经创建过所以这里运行接口是该库已经存在

若创建成功只可以在finder文件中查看
在中终端输入以下命令
隐藏文件
不显示
defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder
显示
defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder
命令执行完成之后可以在/.cocoapods/repos/中查看

至此索引库创建完毕。
3、创建远程代码库

4、创建本地代码库
1) 创建本地代码组件模版库
pod lib create <组件名>
组建名可以和远程代码库一致(根据自身需求对下面的提示信息做选择就好)
最后会在本地创建工程


2)以下便是刚刚创建的工程
编译运行通过看下效果。在Xcode彻底删除ReplaceMe.m文件,接着把自己封装好的组件化代码的文件夹拖入到组件FPS的classes路径下


3)接着cd到Example下进行pod install (把刚才拖入到classes里的文件夹pod进来,这里会通过podfile里面默认的设置,自动把classes里的文件pod过去)
编译组件看是否报错,编译通过后需要修改podspecs索引文件,一般需要修改下面几个问题。
1、修改版本号 2、修改项目的简单概述和详细描述 3、修改homepage和source地址 4、添加依赖库

4) 编译运行通过后,提交组件到远程代码库并打tag.
git add .
git commit -m “xxx”
git remote add origin 远程代码仓库地址
git push origin master 或者 git push -u origin master(一般第一次提交用)
git tag 版本号/git tag -a 版本号 -m “version 版本号”(注:这里的版本号必须和podspec里写的版本号一致)
git tag 查看版本号是否提交成功
git push --tags
在这过程中如果执行 <git remote add origin 远程代码仓库地址> 的时候出现<remote origin already exists> 则执行<git remote rm origin>再执行<git remote add origin 远程代码仓库地址>
执行<git push origin master 或者 git push -u origin master(一般第一次提交用)> 如果遇到<master -> master (fetch first)> 则执行git push origin master -f 或者 git push -u origin master -f(一般第一次提交用)

5)通过
pod spec lint --allow-warnings
命令验证podspec索引文件
(注:pod lib lint是检索本地索引文件,pod spec lint 是本地和远程库同时检索)

6)验证通过后,
pod repo push <本地索引库> <索引文件名> - -allow-warnings
提交索引文件到远程索引库。

本地索引库可以看到

在github可以看到提交上来的代码

大功告成,接下来便可以在其他工程中pod导入该组件。