创建配置仓库 SPSpecs
。所有的配置按照包名、版本号分门别类的存放在这个仓库,这个仓库只用来存放spec文件,不存放代码。复制仓库代码执行命令:
pod repo add SPSpecs http://code.starlinke.cn/gaowenli/spspecs.git

查看是否添加成功
pod repo list

- 创建代码仓库
SPLib
。克隆仓库到本地,cd 到仓库文件夹,执行pod spec create SPLib
创建SPLib.podspec
文件。
pod spec create SPLib
SPLib.podspec
文件内容
Pod::Spec.new do |spec|
spec.name = "SPLib"
spec.version = "0.0.1"
spec.summary = "A short description of SPLib."
spec.homepage = "http://code.starlinke.cn/gaowenli/splib"
spec.license = "MIT"
spec.author = { "高文立" => "gaookey@gmail.com" }
spec.platform = :ios, "10.0"
spec.source = { :git => "http://code.starlinke.cn/gaowenli/splib.git", :tag => "#{spec.version}" }
spec.source_files = "Classes", "Classes/**/*"
spec.resources = "Resources/*.png"
spec.swift_version = "5.0"
spec.dependency "SnapKit"
end
如果私有库组件库过多,需要分层文件夹显示则需要使用 subspec
:
#spec.source_files = "Classes", "Classes/**/*"
#spec.resources = "Resources/*.png"
spec.subspec 'GOImagesCarouselView' do |s|
s.source_files = "Classes/GOImagesCarouselView/**/*"
s.resources = "Resources/GOImagesCarouselView/*.png"
end
上传项目到 git
仓库,创建 Release
版本,版本号需要与 SPLib.podspec
文件中的版本号保持一致。

验证 podspec
pod spec lint --allow-warnings

提交podspec文件到索引库
pod repo push SPSpecs SPLib.podspec --allow-warnings
添加成功如下图所示

添加成功后,索引库 SPSpecs
中会自动出现 SPLib
,SPLib
中只包含 SPLib.podspec
文件。


成功后即可搜索 SPLib
库
pod search SPLib

对已有库进行更新,需要创建 Release
版本,更改 SPLib.podspec
文件版本号,重新执行 pod repo push SPSpecs SPLib.podspec --allow-warnings
即可。
demo 测试 SPLib
库
新建 demo 工程,使用pod安装 SPLib
库
source 'https://github.com/CocoaPods/Specs.git'
source 'http://code.starlinke.cn/gaowenli/spspecs.git'
target 'demo' do
use_frameworks!
pod 'SPLib'
end
pod 成功后,导入 SPLib
后即可使用

网友评论