创建自己的cocoapods库

547 阅读2分钟

最近在整理自己的简历,发现简历上面没有拿的出手的干货,都是一些“负责什么界面、维护什么迭代”,全是业务、业务、业务。 创建cocoapods库过程中全程自己摸索,很苦逼,很蛋疼 创建空文件 用于承载pod给你创建好的工程

  1. 在终端下输入 pod lib create xxxx(你的库名)

1
然后提示你会让你回答几个问题,注意大小字母和空格的问题

  1. 然后会自动为你创建一个工程,并自动打开,这里让你省很多事(在没有找到这个方法事自己在坑里面转了几个小时)

2
此时已经进行到一半了,进入我们熟悉的Xcode中

3

  1. 看到我们的工程中有一个XXX.podspec文件,在这里面配置我们的信息,改动的地方很少。 但是注意 “s.description” 文字一定要比“s.summary ”长,否则等会验证会出现error 红框的地方就是我们的库代码

输入下面的代码,验证我们的配置文件有没有错误,很坑很坑很坑很坑

➜  GCYBase git:(master) pod lib lint GCYBase.podspec 

 -> GCYBase (0.1.0)

GCYBase passed validation.
  1. 要是如上图那么恭喜你了,可以进行下一步操作,提交到Git上 此时我们的Git上是没有这个工程的,所以我们要去创建一个新的工程, Repository name 就是你的库名字 其他的都不要选择了,语法和证书都不要选,否则会有冲突的,因为上面已经自动给你创建了一个工程,里面已经包含了下面的配置信息。

4

git add . 
git commit -m “Initial Commit" 
git remote add origin https://github.com/xxx/xxx.git 
git push -u origin master
  1. 最后的验证,要是没有问题,显示如下
➜  GCYBase git:(master) ✗ pod spec lint GCYBase.podspec

 -> GCYBase (0.1.2)

Analyzed 1 podspec.

GCYBase.podspec passed validation.

  1. 最后提交我们的pod 这个是失败的,更新pod就可以了
➜  GCYBase git:(master) ✗ pod trunk push GCYBase.podspec 
Updating spec repo `master`
[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
➜  GCYBase git:(master) 

根据提示运行

➜  GCYBase git:(master) pod repo update --verbose

等待pod更新完成

5

重新运行 pod trunk push GCYBase.podspec 总于等到你

➜  GCYBase git:(master) ✗ pod trunk push GCYBase.podspec
Updating spec repo `master`

CocoaPods 1.5.0 is available.
To update use: `sudo gem install cocoapods`

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.5.0

Validating podspec
 -> GCYBase (0.1.2)

Updating spec repo `master`

CocoaPods 1.5.0 is available.
To update use: `sudo gem install cocoapods`

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.5.0


--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  GCYBase (0.1.2) successfully published
 📅  April 19th, 03:50
 🌎  https://cocoapods.org/pods/GCYBase
 👍  Tell your friends!
--------------------------------------------------------------------------------
➜  GCYBase git:(master) ✗ 

然后就是默默的等待吧,大概两个工作日 可以通过 search xxx 查找自己的pod

总结

还是有很多的不足