创建⾃⼰的私有库:

⼀: 创建私有索引库

1: 创建远程索引库仓库,存放spec⽂件,⽤来找到私有组件地址


image.gif

2)将远程私有库关联到本地cocos repo库中:
本地cocosPod仓库地址⼀般是:~/.cocoapods/repo
使⽤终端:
cd /Users/lee/.cocoapods/repos
pod repo add XCToolSpec http://123.57.42.55:3000/zmg/
XCToolSpec.git

⼆ : 创建代码源码私有库

1: 创建本地⼯程模版:
cd /Users/lee/Desktop/组件⼯程
pod lib create XCTool


image.gif

创建成功后XCode⾃动打开⼯程


image.gif

2: 编写源代码:


image.gif

3: 调⽤demo:(如果⽆法调⽤类,需要在类名前加上public,⽅法名也要
加,或者open,权限控制)


image.gif

image.gif

4: 创建远程代码私有仓库:


image.gif

三: 修改组件podSpec配置⽂件

image.gif

四: ⼯程模版提交到私有库:

终端提交:
cd /Users/lee/Desktop/组件⼯程/XCTool
git add .
git commit -m"创建私有组件:⼯具库"
git tag 0.1.0
git remote add origin http://123.57.42.55:3000/zmg/XCTool.git
git push -u origin master
git push --tag

五: ⼯程验证:(注意需要加上忽略警告,

否则会出现失败)
pod lib lint --allow-warnings


image.gif

远程⽂件验证:
pod spec lint --allow-warnings


image.gif

podSpec⽂件上传⾄repo仓库:
pod repo push XCToolSpec XCTool.podspec --allow-warnings
出现失败:
[!] /usr/bin/git -C /Users/lee/.cocoapods/repos/XCToolSpec pull
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
解决⽅式:仓库没有设置 README.md ⽂件导致
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin http://123.57.42.55:3000/zmg/XCToolSpec.git
git push -u origin master
重新上传:pod repo push XCToolSpec XCTool.podspec --allow-warnings

image.gif

六: 上传成功后:

1: 可以查看到本地索引库和远程索引库中已经添加上了索引⽂件


image.gif

image.gif

2: 执⾏ pod search XCTool 查看是否成功


image.gif

七: 在其他项⽬中使⽤⾃⼰的私有组件库:
新建个测试APP⼯程
创建podfile ⽂件: pod init
在podfile⽂件添加私有组件库地址:
source ‘http://123.57.42.55:3000/zmg/XCToolSpec.git
导⼊组件:pod 'XCTool'

image.gif

安装组件: pod install


image.gif

使⽤组件:


image.gif

其他:
Swift只有单⽂件,没有头⽂件,如何隐藏源码只暴露⽅法名称。
(extension)
如何不暴露.swift⽂件,只提供framework (spec配置⽂件)
组件是如何维护升级的 (git)
⼀个⼤组件能否再拆分⼩组件 (参考⼤⼚公开组件的按需引⼊模式)
私有组件如果还需要依赖其他组件,如封装⽹络库还需要依赖AFN ,该怎么
进⾏处理,依赖的三⽅组件是否和项⽬冲突,该怎么进⾏处理 (spec配置⽂
件)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。