尝试使用CocoaPad

甭管什么原因吧,反正现在要用CocoaPod了,刚开始不知道这是什么玩意儿,后来看了一些介绍明白了,其实就跟vim的插件管理工具Vundle一个意思,CocoaPod就是用来管理第3方库的。自己创建一个项目,你能保证你用的所有代码都是自己从系统接口开始撸出来的吗?不能吧,就算你愿意你老板也不愿意啊,所以这时就需要使用开源的第3方库来帮你完成部分功能,这时问题来了,什么都怕多,如果我用了很多的第3方库,以至于整个项目看起来几乎都是东拼西凑的了,那这么多的库咋管理?如果有个别的库有更新了呢?而且有些库在编译的时候需要添加一些编译变量,比如-Ddebug之类的,这些编译变量在使用Makefile时经常会遇到,就是那个意思。这时难道我要一个一个的去手动修改吗?答案肯定是否定的,这时CocoaPod就可以出场管理这些第3方库了,此时他就跟Vundle的功能一样,什么?你不知道Vundle是什么,那就当我没说吧。

首先是安装。最初我跟着网上的教程稀里糊涂的装了,但是不知道装哪里去了。

 ~/Work/src/ios/audio-stream/ pod setup
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 1275860, done.
  remote: Compressing objects: 100% (2182/2182), done.
  remote: Total 1275860 (delta 1166), reused 37 (delta 37), pack-reused 1273503
  Receiving objects: 100% (1275860/1275860), 398.79 MiB | 1.57 MiB/s, done.
  Resolving deltas: 100% (628639/628639), done.
  Checking connectivity... done.
  Checking out files: 100% (156551/156551), done.
Setup completed
 ~/Work/src/ios/audio-stream/ ls

执行上面的命令之后,仔细研究了一下,原来是在~/.cocoapods下面创建了一个索引文件。接下来就需要使用pod来下载安装第3方库了。这时我又一次疑惑了,该在哪个目录下载呢?突然醒悟了,当然是在哪里使用下载到哪个目录了,于是用xcode临时创建了一个project,使用命令行进入到该路径下,在根据教程操作。
比如说我刚才用xcode创建的project叫testpod,

 ~/Work/src/ios/testpod/ ls
testpod           testpod.xcodeproj testpodTests      testpodUITests

执行

vi Podfile

最开始,按照教程的例子Podfile的内容是下面这个样子的:

platform :ios
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.0.0'
pod 'ASIHTTPRequest'
pod 'RegexKitLite'

于是在安装那些个库的时候遇到下面的提示:

 ~/Work/src/ios/testpod/ pod install
Analyzing dependencies
[!] The dependency `JSONKit (~> 1.4)` is not used in any concrete target.
The dependency `Reachability (~> 3.0.0)` is not used in any concrete target.
The dependency `ASIHTTPRequest` is not used in any concrete target.
The dependency `RegexKitLite` is not used in any concrete target.

去查了一下,这是因为没有指定谁来用这些库的原因,即需要指明谁来用它们,于是改成下面这样:

platform :ios
target 'testpod' do
        pod 'JSONKit', '~> 1.4'
        pod 'Reachability', '~> 3.0.0'
        pod 'ASIHTTPRequest'
        pod 'RegexKitLite'
end

testpod就是刚才创建的project名字。再次执行

 ~/Work/src/ios/testpod/ pod install
Analyzing dependencies
Downloading dependencies
Installing ASIHTTPRequest (1.8.2)
Installing JSONKit (1.4)
Installing Reachability (3.0.0)
Installing RegexKitLite (4.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `testpod.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 4 dependencies from the Podfile and 4 total pods installed.
 ~/Work/src/ios/testpod/

这时就已经下载安装好指定的第3方库了,同时需要注意的是,以后再打开工程是需要打开testpod.xcworkspace这个文件,而不是原来的那个xcodeproj文件了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值