老手可完全略过, 其它废话不多说...
一. 安装
打开终端(Terminal), 输入命令
sudo gem install cocoapods
还是提示无法安装可尝试
sudo gem install cocoapods --user
二. pod命令使用
pod init- 在项目的根目录运行, 生成一份
Podfile文件 - 可自行创建
Podfile文件, 不使用此命令
- 在项目的根目录运行, 生成一份
pod deintegrate- 在项目根目录运行, 移除项目
cocoapods依赖管理相关的所有设置(*.xcodeproj里面的build setting相关设置), 一般用不到
- 在项目根目录运行, 移除项目
pod install- 按照
Podfile的设置(版本号、仓库索引源...)安装依赖库, 并且生成/更新Podfile.lock(记录依赖库的依赖关系、版本号、仓库索引源...)
- 按照
pod update- 按照
Podfile的设置并结合Podfile.lock(必须有)进行版本升级
- 按照
一般使用
pod init # 初始化出一份Podfile文件Podfile文件内添加三方库pod install # 项目首次安装依赖库pod update # 日常根据Podfile设定的规则进行版本更新
小技巧
pod init和pod update每次运行都会先更新仓库索引源数据, 略略费时间, 可以改为手动更新可在后面增加参数
--no-repo-update, 可以安装/更新时不更新仓库索引源pod install --no-repo-updatepod update --no-repo-update
手动更新
仓库索引源pod repo update
三. Podfile
pod init生成的模板
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'iOSDemo' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for iOSDemo
endplatform: 设定项目兼容的平台和版本号target: 某个target依赖库安装配置里面填写一些需要安装的依赖库和配置
pod {依赖库的名称}, 比如pod 'AFNetworking',pod 'AFNetworking', ~> 1.0
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'iOSDemo' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for iOSDemo
pod 'AFNetworking'
end依赖库版本设置
= 0.10.1版本> 0.1任何大于0.1版本>= 0.1任何大于或等于0.1版本< 0.1任何小于0.1版本<= 0.1任何小于或等于0.1版本~> 0.1.20.1.2(包括)到1.0.0(不包括)版本~> 0.1.3-beta.0beta的0.1.3版本, 和release的0.1.3(包括)到2.0.0(不包括)版本
版本语义说明(有兴趣可以了解下)
Semantic Versioning: https://semver.org/lang/zh-CN/
RubyGems Versioning Policies: https://guides.rubygems.org/patterns/#semantic-versioning