最近在学习Swift时需要使用CocoaPods管理第三方库,然后找了篇文章了解了下,为方便以后回忆,所以把相关内容记录下来
参考文章链接:http://www.cocoachina.com/swift/20150630/12305.html
操作步骤:
1.CocoaPods 安装集成不在赘述,参考文章中有详细介绍
2. 打开终端,进入工程所在目录 cd 项目路径
3. 使用命令 :pod init 生成 Podfile 文件
4.使用Xcode打开并编辑 Podfile ,相关命令 open -a Xcode Podfile,打开时内容应该是这样
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'YiPeiForSwift' do
end
然后修改成如下内容
# Uncomment this line to define a global platform for your project
# Uncomment this line if you're using Swift
platform :ios, '8.0'
use_frameworks!
target 'YiPeiForSwift' do
end
5.搜索自己需要的第三方库 如 pod search AFNetworking,选择自己需要的版本后,添加到 Podfile 文件中
# Uncomment this line to define a global platform for your project
# Uncomment this line if you're using Swift
platform :ios, '8.0'
use_frameworks!
target 'YiPeiForSwift' do
pod 'AFNetworking', '~> 3.0.4'
end
6.终端使用 pod install 下载安装相应的库到自己的项目中,安装完成就可以使用了
另外:如果,因为CocoaPods版本过低而无法安装:
不想升级CocoaPods,可在Podfile的最上面加上这句 source "https://github.com/CocoaPods/Old-Specs"
如果要升级CocoaPods,在终端输入
sudo gem install -n /usr/local/bin cocoapods –pre 进行升级,如果升级遇到问题,可参考文章:
http://blog.csdn.net/wyz670083956/article/details/53517136