iOS 组件化开发之使用CocoaPod制做本身的远程私有库

  随着应用需求逐步迭代,应用的代码体积将会愈来愈大,为了更好的管理应用工程,咱们开始借助CocoaPods版本管理工具对原有应用工程进行拆分。可是仅仅完成代码拆分还不足以解决业务之间的代码耦合,为了更好的让拆分出去的业务工程可以独立运行,必须进行组件拆分而且实现组件服务化。git

   组件化开发优势:github

    1.组件和组件之间没有明确的约束。xcode

    2.组件单独开发、单独测试,不能揉入主项目中开发,测试也能够针对性的测试。ruby

  组件主要分为三类:工具

    基础功能组件:组件化

    基础 UI 组件:测试

    产品业务组件:fetch

  使用 CocoaPods 制做私有库实现过程:spa

  一、建立索引库:code

    可以使用 GitHub、Gitlab、Gitee、等,以 GitHub 为例:

    

  二、将建立的索引库添加到本地 Cocoapods 仓库中:

    pod repo add UCKit https://github.com/zhangtibin/UCKit.git

    

    路径是:~/.cocoapods/repos

  三、建立模板:

    pod lib create UCKit

  

  按提示输入选择后,建立完成,会自动打开 Xcode 工程:

  

  

  在 Classes 目录下,放入须要添加组件的文件:

  

  进入 Example 目录下,执行:pod install。

   

  四、**.podspec 文件中更改模板文件相关信息:

  

  五、验证 .podspec 文件:

    pod lib lint UCKit.podspec --allow-warning     

 

  六、将制做好的组件上传至 GitHub

    git remote add origin https://github.com/zhangtibin/UCKit.git

    git push -u origin master

   若是出现报错时,以下,能够采用修改冲突文件,并提交至 GitHub

  

  

  提交完以后

  

  七、使用:

    pod 'UCKit' , :git =>'https://github.com/zhangtibin/UCKit.git' 

 

 

  在执行:pod lib lint UCKit.podspec --allow-warning

  出现错误:- ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices

  

  xcode设置里面,将Command line Tools设置一下,在Xcode>preferences>Locations里面,设置以后再运行终端便可。

  

  解决后,当出现 ** passed validation表示验证成功:

  

  执行:git push -u origin master

  报错:

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/zhangtibin/UCKit.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

  缘由:远程repository和我本地的repository冲突致使的,而我在建立版本库后,在github的版本库页面点击了建立README.md文件的按钮建立了说明文档,可是却没有pull到本地。这样就产生了版本冲突的问题。

   解决方案:push前先将远程repository修改pull下来。   

  $ git pull origin master

  $ git push -u origin master

  推送以后,就会在 GitHub 上看到新提交的

相关文章
相关标签/搜索