中山企业网站建设,新软件如何推广,深圳平面设计公司排名榜,高效的客户管理crm系统一、创建私有库索引
步骤1是在没有索引库的情况下或者是新增索引的时候才需要用到#xff08;创建基础组件库#xff09; 首先在码云上建立一个私有库索引#xff0c;起名为SYComponentSpec 二、本地添加私有库索引
添加私有库索引
pod repo add SYComponentSpec https:/…一、创建私有库索引
步骤1是在没有索引库的情况下或者是新增索引的时候才需要用到创建基础组件库 首先在码云上建立一个私有库索引起名为SYComponentSpec 二、本地添加私有库索引
添加私有库索引
pod repo add SYComponentSpec https://gitee.com/sun-shiyu/sycomponent-spec三、创建基础组件库
当你需要新建组件的时候就在这里开始如果是想修改原有的库就可以直接在之前的组件仓库里面修改即可
1.在码云上创建组件库 命名为SYBasicComponents如图 2.创建SYBasicComponents本地库 默认创建路径/Users/sunshiyu/SYBasicComponents 。
pod lib create SYBasicComponents最后项目本地组件库创建完成后会自动打开项目。
3.在私有库导入自己的代码
将Classes文件夹下面的ReplaceMe.m文件删除掉替换成你要上传私有库的代码这里导入简单的两个测试文件
// SYLog.h(void)logger;// SYLog.m(void)logger {NSLog(-------- Log --------);
}4.更新这个工程的pod库
cd 到 Example文件下执行 pod install
5.修改.podspec文件 有两个属性需要注意改下 s.homepage私有代码仓库的地址 https://gitee.com/sun-shiyu/sybasic-components s.source私有代码仓库的源地址 https://gitee.com/sun-shiyu/sybasic-components.git
其他属性根据需要自行配置。
6.将私有库push到远程仓库
注意远端需要有个master分支这里先创建一个master分支 cd /Users/sunshiyu/SYBasicComponents git branch mastergit checkout mastercommit代码到本地然后push到远端 git branch (检查当前所在分支)git status (查看当前git存了什么文件)git add . (将所有文件缓存到待提交文件区域)git commit -m 上传组件git remote add origin https://gitee.com/sun-shiyu/sybasic-components.git (私有库git仓库地址)git push -f origin master (将代码推送到远程私有库git仓库的master分支上面已经创建了)git tag 0.1.0 (这里的版本号必须和podspec里面写的版本号一致git push -- tags (提交tag)7.本地和远程校验
1.本地校验在当前私有库目录下输入命令
pod lib lint --private --allow-warnings校验成功SYBasicComponents passed validation.
2.远程验证在当前私有库目录下输入命令
pod spec lint --private --allow-warnings校验成功SYBasicComponents.podspec passed validation.
8.提交索引文件到远程索引库
1.所有验证通过之后要将spec文件推送到最开始创建的私有库索引库当中
cd 到私有库项目目录 pod repo push 本地索引库名称 索引文件名 --allow-warnings 本地索引库名称在 /Users/sunshiyu/.cocoapods/repos 下的私有库索引项目名称 索引文件名就是以 podspec 结尾的,注意不要弄错
例如输入命令
pod repo push SYComponentSpec SYBasicComponents.podspec --allow-warnings2.推送去之后在本地索引库中查看如下图
在 getee 远端查看如下图 四、使用基础组件库
随便创建一个项目名为 SYSpecDemo 初始化 pod cd /Users/sunshiyu/Desktop/SYSpecDemopod initpod install打开编辑 podfile 文件
open podfile如下
# Uncomment the next line to define a global platform for your project
platform :ios, 11.0# source 添加对应的索引库否则会pod install失败
source https://gitee.com/sun-shiyu/sycomponent-spec.gittarget SYSpecDemo do# Comment the next line if you dont want to use dynamic frameworksuse_frameworks!# Pods for SYSpecDemo# pod 对应组件可以对应版本pod SYBasicComponentsend再次
pod install就可以看到这个库
导入头文件使用该库
#import SYBasicComponents/SYLog.h// 打印 log
[SYLog logger];五、组件库依赖第三方库
如果我们的组件库需要依赖第三方库例如 AFNetWorking、YYModel 等操作如下
1.修改组件库的 SYBasicComponents.podspec 文件添加依赖 然后组件库执行 Example 项目 执行 pod install。
2.同上面第6步将组件库修改的代码提到远端。记住一定要记得打 tag且要与索引库的 version 保持一致 。 git tag 0.2.0 (这里的版本号必须和podspec里面写的版本号一致git push -- tags (提交tag)3.提交索引库远端同上面的第8步
pod repo push SYComponentSpec SYBasicComponents.podspec --allow-warnings4.修改主项目的 podfile 文件加入 github CocoaPods 索引库用来加载github三方库的
source https://github.com/CocoaPods/Specs.git然后执行 pod install。
以上是使用 pod SYBasicComponents 的方式使用组件库也就是远程的方式这种方式需要没更新组件库后都要打 tag 以及修改 spec 的version然后修改主项目的 podfile 文件根据情况也可能不需要要修改最后主项目重新 pod install 。这样就能得到远程组件库最新的代码缺点是主项目每次想更新组件库的最近代码都需要组件库打 tag 更新组件库的版本如何实现只要组件库有代码更新主项目直接拉最新的代码呢答案是引用本地索引库的方式我们只需要修改主项目的 podfile 文件如下
# Uncomment the next line to define a global platform for your project
platform :ios, 11.0# source 添加对应的索引库否则会 pod install 失败
# source https://gitee.com/sun-shiyu/sycomponent-spec.git
source https://github.com/CocoaPods/Specs.gittarget SYSpecDemo do# Comment the next line if you dont want to use dynamic frameworksuse_frameworks!# Pods for SYSpecDemo# pod 对应组件可以对应版本# 方式一、引用远端组件库# pod SYBasicComponents# 方式二引用本地组件库不需要 source https://gitee.com/sun-shiyu/sycomponent-spec.gitpod SYBasicComponents, :path ~/SYBasicComponents/end即使用 pod SYBasicComponents, :path ~/SYBasicComponents/ 的方式来直接引用本地组件库的代码这样拉代码每次都是最新的。我们 pod install 试试看Pods 目录结构变如下图所示 本地组件库 SYBasicComponents 里面就是最新的代码了。因为我们的组件库依赖了 AFNetworking YYModel所以Pods中出现了这两个库。
结束
参考 iOS私有库搭建 iOS组件化搭建私有库