How to create your own Cocoapods and publish to GitHub (Swift)

最近在做一些iOS的工作,偶然接触到创建自己的Cocoapods,看似复杂的东西,其实挺简单的,分享下攻略:

假设你已经:

  • 安装了xcode
  • 安装了Cocoapods

第一步:创建一个空的git

这个就不说了,创建好之后,本地clone,然后进入目录,跑下:

git add README.md
git commit -m “first commit”
git remote add origin https://github.com/xxx/xxx.git
git push -u origin master

第二步:创建pod

之后在该目录下跑:

pod lib create xxx

之后会出现一些问题,如实回答即可

第三步:修改.podspecs文件

上一步完成之后,会自动打开xcode和创建的项目,在项目中有个.podspecs的文件,修改里面的参数,特别是git的地址。然后跑:

pod lib lint

大概率会报错,根据错误修改下相应文件即可

第四步:加入你的lib文件

在pod下,有些找到replaceMe的文件,把你的lib放到这个目录下。记得把replaceMe给删除了。

第五步:上传tag

git add .
git commit -m"Initial Commit"
git remote add origin https://github.com/xxx/xxx.git
git tag 0.1.0
git push origin 0.1.0

完成之后跑下:

pod repo add XXX https://github.com/xxx/xxx.git
pod repo push XXX #刚才你的命名

第六步:使用

上面五步骤基本上完成了整个发布,下面可以直接测试和使用:

source 'https://github.com/xxx/xxx.git'

pod "XXXX" #之前定义的名字

This site Original article All followed" Attribution—NonCommercial—ShareAlike 4.0 (CC BY-NC-SA 4.0) ”。 Please keep the following marks for sharing and interpretation:

Original author: Jake Tao Source: 「如何创建自己的Cocoapods并发布到GitHub(Swift)」

Praise 639
0 0 639

Further reading

Post a reply

Log in can only be commented on later
Share this page
Back to top