目录:
- 什么是CocoaPods
- 如何下载并安装CocoaPods
- 如何使用CocoaPods
什么是CocoaPods
当开发iOS应用时,或多或少的都会引用第三方类库,例如AFNetworking等,一种方式是将第三方类库的源代码下载并添加到项目中,但是当饮用的类库有更新时,就需要重新下载并添加,这种手工添加的方式就非常的麻烦了。
目前CocoaPods是iOS上最常用的类库管理工具,类似于.NET平台的NuGet。通过CocoaPods,只需要几个简单的命令行,就可以将第三方类库下载并添加到项目中,同时也可以很方便的对其进行更新。
CocoaPods官方地址是https://cocoapods.org/
如何下载并安装CocoaPods
CocoaPods官方安装说明
通过上图可以看出,下载安装CocoaPods非常简单,只需要在终端中输入下面命令就可以了。
mac OS系统如何进入终端,如下图:
输入上面命令以后可能会出现两种结果:
结果一:
如果提示:1 gem installed,说明已经下载成功,接下来需要安装,如下步骤:
如何cd到Podfile所在目录:
你 cd 到 Podfile 所在目录 执行如下命令:
$pod install
结果二:
如下地址亲测有效:
$ gem sources -a https://gems.ruby-china.com/
可以通过下面命令来验证你安装的是TB的Ruby镜像。
若出现下面信息,证明上述命令安装成功了。
如果到此模拟器还是启动不起来,那么再调整如下步骤:
总结: 以上内容只是CocoaPods的基本用法,若想研究更高级的用法, 可以参考CocoaPods Wiki:https://github.com/CocoaPods/CocoaPods/wiki