使用场景:

【例如多个项目,需要用到统一的工具类和Base等相关的一套代码。】

这个场景下,就可以做一个私有库把通用的代码放里面,其他项目都可以用pod的方式引入了。

「私有库的好处是,更新的时候很方便,就是跟提交git项目一样,不需要pod校验等工作,方便不少」

步骤如下:

一:首先假设自己原有项目A、B放在workspace下面。

二:在gitlab上创建一个私有项目TestPod,并且克隆到本地的workspace目录下。

三:cd 到 项目TestPod中,创建 podspec

​pod spec create TestPod​

四:修改podspec文件,例如:

Pod::Spec.new do |spec|

spec.name = "TestPod"
spec.version = "0.0.1"
spec.summary = "TestPod"
spec.description = <<-DESC
所有项目公用的私有pod库(注意:s.description一定要比s.summary长)
DESC
spec.homepage = "https://gitlab.risejia.cn/xxxxx/testpod"
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.author = { "xxxx" => "xxxx@163.com" }
spec.ios.deployment_target = '10.0'
spec.swift_version = '5.0'

# 资源和文件
spec.source = { :git => "https://gitlab.risejia.cn/xxx/testpod.git", :tag => "#{spec.version}" }
spec.source_files = 'RisePod/Classes/**/*'
# 目录中展示出Assets
spec.resource_bundles = {
'RisePod' => ['RisePod/Assets/*']
}
# 工具类 -- 「需要在项目中展示的文件夹都需要跟Utils类似的方法写出来」
spec.subspec 'Utils' do |u|
u.source_files = 'RisePod/Classes/**/*'
end

end

五:在自己的项目A、B中的引入方式为: (大小写要注意)

​pod 'TestPod', :path => '../testpod'​

然后pod install ,就会拉下来 TestPod里面的代码和文件了。

拉下来后的大概目录结构为:(TestPod项目里面创建Classes文件夹,然后把需要的业务的代码放里面,比如:Assets、Utils 都放在 Classes里面)

Development Pod -> TestPod -> {Assets、Pod、Support Fils、Utils}

!!需要注意的是 podspec里面的修改,如果 spec.source_files/ spec.subspec等设置不对的话,目录结构就会错,甚至拉不下来里面的代码。