问题
1.iOS 私有库存在的意义
2.整么搭建一个iOS私有库呢
答案
1.iOS 私有库存在的意义
当我们到达一家新的工作单位之后,特别是公司没有iOS项目基础的时候,为了公司项目有技术积累,作为一个有信仰的iOS开发人员就需要搭建公司的 私有库了。搭建私有库的好处就不用我多说了。
2.整么搭建一个iOS私有库呢
2.1 最终结果显示
Tip: cocoapod 整么安装,这里就不做详细解释了,作为一个iOS开发人员,这个是最基础的工具,我就当你掌握这些基本知识了
假设我们开发了一个私有库 LAAlamofire 最终结果应该如下图1.1.png,LASpec 是我们的索引库,LAAlamofire 使我们自己开发的库

2.2 创建流程
- 1.创建自己的索引库 LASpec
在任意目录下执行如下命令:
pod repo add LASpec https://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@github.com/MMSuperD/LASpec.git
索引库的名字: LASpec
索引库的地址: https://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@github.com/MMSuperD/LASpec.git
如果出现如下错误 :fatal: unable to access 'https://github.com/MMSuperD/LASpec.git/': Error in the HTTP2 framing layer
解决方案: 多尝试几次,换个网络尝试
成功后的结果是:在 ~/.cocoapods/repos目录下面新增了 一个 LASpec 文件夹
- 2.创建自己的代码仓库LAAlamofire
在桌面创建自己的代码文件夹:cd 到自己的文件夹目录执行如下代码:
pod lib create LAAlamofire
代码库的名字: LAAlamofire
如果出现 错误: fatal: unable to access 'https://github.com/CocoaPods/pod-template.git/': Error in the HTTP2 framing layer
同样的方式切换网络,多尝试几次
过长中:
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Quick / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> Yes
到这里基本上我们的本地 pod LAAlamofire,基本已经创建完毕了
- 3.修改自己的本地代码库LAAlamofire
LAAlamofire.podspec 文件
核心点(具体什么意思自行查阅):
s.version = '0.1.1'
s.source = { :git => 'https://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@github.com/MMSuperD/LAAlamofire.git', :tag => s.version.to_s }
s.ios.deployment_target = '15.0'
#
# Be sure to run `pod lib lint LAAlamofire.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'LAAlamofire'
s.version = '0.1.1'
s.summary = 'A short description of LAAlamofire.'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://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@github.com/MMSuperD/LAAlamofire.git'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'fan' => 'shdjxywd@163.com' }
s.source = { :git => 'https://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@github.com/MMSuperD/LAAlamofire.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '15.0'
s.source_files = 'LAAlamofire/Classes/**/*'
# s.resource_bundles = {
# 'LAAlamofire' => ['LAAlamofire/Assets/**/*']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.dependency 'Alamofire', '~> 5.6.4'
end
- 4.把我们本地LAAlamofire的代码推到远端仓库
首先 pod install
git add .
git commit -m "init"
git remote add origin https://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@github.com/MMSuperD/LAAlamofire.git
git push origin main -f (这里第一次强制推送到 远端如果你不强制推送到远端,那你就一步一步拉 之后在推 git pull origin main --allow-unrelated-histories --no-rebase,建议强制推送)
自己打tag: git tag 0.1.1
推送tag:git push origin --tags
- 5.本地库,远程库校验
本地库校验
pod lib lint LAAlamofire.podspec --verbose --allow-warnings
远端库校验
pod spec lint --verbose --allow-warnings
- 6.推送本地库在索引库中更新
pod repo push LASpec LAAlamofire.podspec --allow-warnings
网友评论