1.新建一个项目,名字PodTest

2.终端中,cd到项目总目录(注意:包含PodTest文件夹、PodTest.xcodeproj、PodTestTest的那个总目录)
cd /Users/lucky/Desktop/PodTest
3.建立Podfile(配置文件)接着上一步,终端输入 vim Podfile 或者 touch Podfile
新建一个文件,指令:vim Podfile (touch Podfile 也行,注意大小写,通过touch创建的不能直接编辑,还得双击打 开,所以一般用vim那个)。新建这个文件的目的是要告诉CocoaPods我这个工程里需要用到哪些框架。
(vim Podfile)

4.键盘输入 i,进入编辑模式输入
在创建Podfile的时候,可以用这种格式使用:
platform :ios, '8.0'
#use_frameworks!个别需要用到它,比如reactiveCocoa
target 'PodTest' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end
下面是另外一种写法:
platform :ios, '8.0'
#use_frameworks!个别需要用到它,比如reactiveCocoa
def pods
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end
target 'PodTest' do
pods
end
以上两种方法里面的 PodTest 记得替换为自己工程里面的target。这样就基本OK了(use_frameworks! 这个是个别需要的,这里修改一下,可以把我上面的代码中的这一行【删除】)
5.然后按Esc,并且输入“ :”号进入vim命令模式,然后在冒号后边输入wq

6.注意:键盘输入 :后,才能输入wq。回车后发现PodTest项目总目录中多一个Podfile文件

激动人心的时刻到了:确定终端cd到项目总目录,然后输入 pod install,等待一会,大约3分钟。

查看项目根目录:

注意:现在打开项目不是点击 PodTest.xodeproj了,而是点击 PodTest.xcworkspace
打开项目后看到项目结构并且测试一下,就可以了!
网友评论