5个步骤发布一个iOS组件

5个步骤发布一个iOS组件,第1张

1、clone组件模板

首先我们来为项目创建一个关于题库的功能组件LYQuestionKit。在桌面创建一个名为Demo的文件夹,使用终端切换到该文件夹目录下。

pod lib create LYQuestionKit //执行下面的命令pod会自动把https://github.com/CocoaPods/pod-template.git 远程的模板clone到本地
复制代码

把想要分享的(.h,.m)文件放在ReplaceMe.m 同级目录,删除ReplaceMe.m文件。

如果你正在面试,或者正准备跳槽,不妨看看我精心总结的iOS大厂面试资料:https://gitee.com/Mcci7/i-oser 来获取一份详细的大厂面试资料 为你的跳槽加薪多一份保障

2、开发完后把组件代码与远程仓库关联

2.1、在公司的git服务器(或者GitHub上)创建一个LYQuestionKit仓库。

2.2、首先在终端上切换到桌面的Demo文件夹,然后切换到LYQuestionKit项目目录下,执行下面的命令。

2.3、把LYQuestionKit项目和git服务器远程的仓库关联,并把代码推到git服务器上。

//从命令行创建一个新的仓库
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com:99/zly/LYQuestionKit.git
git push -u origin master
复制代码
3、打tag

为当前开发的组件代码设置tag、tag版本号和podspec的 s.version两者必须统一。

git tag '0.0.1' && git push --tags  //每次提交更新都需要更新
复制代码
4、配置podspec

配置podspec包括 source_files、dependency、source、version等信息,若有子文件夹想要设置子模块,需要配置subspec,对编辑好的podspec进行验证。

//1、配置podspec格式如下
//pod名
s.name             = 'LYQuestionKit'
//版本号
s.version          = '0.0.1'
//要分享源代码的仓库地址,可以是自己的私有仓库
s.source = { :git => 'https://github.com:99/zly/LYQuestionKit.git', :tag => s.version.to_s 
//源文件地址
s.source_files = 'LYQuestionKit/Classes/**/*'
//设置第三方库的依赖
s.dependency 'FMDB', '~>2.7.2'
//子模块
s.subspec 'LYConfig' do |s|
  s.source_files = 'LYQuestionKit/Classes/LYConfig/*'
  s.public_header_files = 'LYQuestionKit/Classes/LYConfig/*.h'
end

//2、找到Example下面的podfile文件进行pod install

//3、验证podspec是否正确,pod lib lint 不会访问网络
pod lib lint --allow-warnings  #本地验证,如果验证成功会提示LYQuestionKit passed validation.
复制代码
5、发布到 Cocoapods
//1、验证 `podspec` 文件信息是否可以通过验证 pod spec lint checks the external repo and associated tag.
pod spec lint

//2、提交之前要先通过 trunk 注册生成一条会话,点击邮箱验证,不然第三步过不了
// pod trunk register 邮箱 用户名 描述
pod trunk register [email protected] zhouluyao --description=LYQuestionKit题库 

//3、将 podspec 提交给 CocoaPods 了,这个文件将是别人搜索你的组件的索引。
pod trunk push LYQuestionKit.podspec --allow-warnings

//4、搜索不到的解决方案
pod search LYQuestionKit
[!] Unable to find a pod with name, author, summary, or description matching `LYQuestionKit`
如果搜索不到,删除本地的搜索文件,命令 :
rm ~/Library/Caches/CocoaPods/search_index.json
重新 search 产生新的搜索文件。
复制代码
组件代码发布新版本则需要打新的 tag,重新编辑 podspec 文件,然后再次提交给 CocoaPods。

参考资料: iOS 组件化

作者:zhouluyao
链接:https://juejin.cn/post/7045662353158537247

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/996562.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存