从零开始建立CocoaPods私有库

为何要建立CocoaPods私有库?

  • 避免重复的造轮子
  • 节约时间,方便管理本身的代码
  • 精益求精

建立CocoaPods私有库

1.建立私有仓库工程

执行命令pod lib create SmartBeeKit,而后根据实际状况回答问题,本文以建立SmartBeeKit为例。ios

2.将编写好的源码文件拷贝到SmartBeeKit/Classes目录下

3.在SmartBeeKit/Example目录下执行pod install,而后打开SmartBeeKit.xcworkspace工程,编写测试代码,run😁,验证代码是否导入成功

4.在GitHub或者其余代码托管平台上,建立SmartBeeKit远程仓库https://github.com/xxx/SmartBeeKit.git

5.修改SmartBeeKit.podspec文件,里面 包含了大量的注释说明以及每一个参数的含义及用法

s.name:名称,pod search 搜索的关键词
s.version:版本
s.summary:简介,pod search 搜索的关键词
s.homepage:主页地址,例如Github地址
s.license:许可证
s.author:做者
s.social_media_url:社交网址
s.platform:平台
s.source:Git仓库地址,例如在Github地址后边加上 .git 就是Git仓库地址,常见写法以下
s.source_files:须要包含的源文件,常见的写法以下
s.resources:须要包含的图片等资源文件
s.dependency:依赖库,不能依赖未发布的库
s.dependency:依赖库,若有多个能够这样写
s.requires_arc:是否要求ARC
复制代码

6.运行pod lib lint SmartBeeKit.podspec验证私有库正确性,出现SmartBeeKit passed validation.表示验证成功。

7.将包含配置好的 .podspec 的项目提交到第4步建立的仓库上,并给此次提交打上 tag,到此,私有库就建立好了,good luck!!!

如何引用本身建立的私有库?

有两种方式引用本身建立的私有库git

1.直接引用,不使用索引库,所见即所得😁

platform :ios, '9.0'
target 'TestPod' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    # use_frameworks!

    # Pods for TestPod
    pod 'SmartBeeKit', :git => 'https://github.com/xxx/SmartBeeKit.git'
end
复制代码

2.建立私有的cocoapods索引库,而后在引用它

2.1 在GitHub码云等代码托管开发平台上创建一个空的仓库,我建立了一个Rbbin的空仓库,见下图

2.2 将本地索引库与远程索引库作关联

pod repo add Rbbin https://github.com/xxx/Rbbin.gitgithub

能够用下面的命令,来查看是否关联成功markdown

pod repooop

能够用下面的命令,来删除索引库测试

pod repo remove [索引库名字]ui

2.3 将私有仓库push到索引库

pod repo push Rbbin SmartBeeKit.podspec url

2.4 配置podfile文件以下,而后pod install
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/xxx/Rbbin.git'

platform :ios, '9.0'

target 'TestPod' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    # use_frameworks!

    # Pods for TestPod
    # pod 'SmartBeeKit', :git => 'https://github.com/xxx/SmartBeeKit.git'
    pod 'SmartBeeKit', '~> 0.0.1’
end
复制代码
2.5 如何更新维护?

若是有新版本了,好比1.0.0,就须要再次执行命令 pod repo push Rbbin SmartBeeKit.podspec,就能够更新上去.spa

2.6 如何删除podspec索引库中的私有仓库呢?

其实很简单,只须要cd到~/.cocoapods/repos/Rbbin目录下,删掉库目录code

rm -rf SmartBeeKit/

而后push到远端仓库

git add .
git commit -m "delete SmartBeeKit"
git push origin master
复制代码

建立本身的公有库(未完待续...)

相关文章
相关标签/搜索