重装系统,升级Xcode7之后,发现安装不了CocoaPods,
直接上步骤:
* 安装 CocoaPods *
步骤1 - 安装 RVM
RVM 是干什么的这里就不解释了,后面你将会慢慢搞明白。
$ curl -L https://get.rvm.io | bash -s stable
期间可能会问你sudo管理员密码,这里可能需要等待一段时间后就可以成功安装好 RVM。
案例信息如下:
lihuifengdeMacBook-Pro:~ lihuifeng$ curl -L https://get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 184 100 184 0 0 8 0 0:00:23 0:00:21 0:00:02 8
100 22817 100 22817 0 0 523 0 0:00:43 0:00:43 –:–:– 1056
Downloading https://github.com/wayneeseguin/rvm/archive/1.26.10.tar.gz
Downloading https://github.com/wayneeseguin/rvm/releases/download/1.26.10/1.26.10.tar.gz.asc
Found PGP signature at: ‘https://github.com/wayneeseguin/rvm/releases/download/1.26.10/1.26.10.tar.gz.asc‘,
but no GPG software exists to validate it, skipping.
Upgrading the RVM installation in /Users/lihuifeng/.rvm/
RVM PATH line found in /Users/lihuifeng/.profile /Users/lihuifeng/.bashrc /Users/lihuifeng/.zshrc.
RVM sourcing line found in /Users/lihuifeng/.bash_profile /Users/lihuifeng/.zlogin.
Upgrade of RVM in /Users/lihuifeng/.rvm/ is complete.
lihuifeng,
#
Thank you for using RVM!
We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
~Wayne, Michal & team.
In case of problems: http://rvm.io/help and https://twitter.com/rvm_io
Upgrade Notes:
- No new notes to display.
--这里就表示已经成功安装了--
然后,载入 RVM 环境
source /.rvm/scripts/rvm检查一下是否安装正确:输入命令rvm−v,如果正确会列出RVM版本如下所示: rvm -v
A RVM version 1.26.10 (latest) is installed yet 1.25.28 (stable) is loaded.
Please do one of the following: - ‘rvm reload’
- open a new shell
- ‘echo rvm_auto_reload_flag=1 >> ~/.rvmrc’ # for auto reload with msg.
‘echo rvm_auto_reload_flag=2 >> ~/.rvmrc’ # for silent auto reload.
步骤2 - 用 RVM 安装 Ruby 环境
输入命令 $ rvm install 2.0.0$ rvm install 2.0.0
同样继续等待漫长的下载,编译过程,完成以后就安装好了。
A RVM version 1.26.10 (latest) is installed yet 1.25.28 (stable) is loaded.
Please do one of the following:
* ‘rvm reload’
* open a new shell
* ‘echo rvm_auto_reload_flag=1 >> ~/.rvmrc’ # for auto reload with msg.
* ‘echo rvm_auto_reload_flag=2 >> ~/.rvmrc’ # for silent auto reload.
步骤3 - 设置 Ruby 版本
RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本
$ rvm 2.0.0 –default
同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本
测试是否正确
lihuifengdeMacBook-Pro:~ lihuifeng
ruby−vruby2.0.0p481(2014−05−08revision45883)[x8664−darwin13.1.0]lihuifengdeMacBook−Pro: lihuifeng
gem -v
2.2.2
这有可能是因为Ruby的默认源使用的是cocoapods.org,国内访问这个网址有时候会有问题,网上的一种解决方案是将远替换成淘宝的,替换方式如下:
$gem source -r https://rubygems.org/
$ gem source -a https://ruby.taobao.org
lihuifengdeMacBook-Pro:~ lihuifeng$ gem source -r https://rubygems.org/
https://rubygems.org/ removed from sources
lihuifengdeMacBook-Pro:~ lihuifeng$ gem source -a https://ruby.taobao.org
https://ruby.taobao.org added to sources
要想验证是否替换成功了,可以执行:
$ gem sources -l
正常的输出结果:
lihuifengdeMacBook-Pro:~ lihuifeng$ gem sources -l
* CURRENT SOURCES *
这里就表示已经把Ruby环境成功的安装到了Mac 上了。
** 使用 CocoaPods **
使用CocoaPods
a 新建一个项目,名字PodTest
b 终端中,cd到项目总目录(注意:包含PodTest文件夹、PodTest.xcodeproj、PodTestTest的那个总目录)
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
cd /Users/yinzi_boy/Desktop/PodTest
c 建立Podfile(配置文件)
接着上一步,终端输入 vim Podfile
键盘输入 i,进入编辑模式,输入
platform :ios, ‘7.0’
pod ‘MBProgressHUD’, ‘~> 0.8’
然后按Esc,并且输入“ :”号进入vim命令模式,然后在冒号后边输入wq
注意:键盘输入 :后,才能输入wq。回车后发现PodTest项目总目录中多一个Podfile文件
激动人心的时刻到了:确定终端cd到项目总目录,然后输入 pod install,等待一会,大约3分钟。
查看项目根目录:
注意:现在打开项目不是点击 PodTest.xodeproj了,而是点击 PodTest.xcworkspace
打开项目后看到项目结构并且测试一下:
运行结果:
查找第三方库文件,通过终端
pod search 命令进行查找
CocoaPods 导入第三方库头文件自动补齐
使用了一段时间CocoaPods来管理Objective-c的类库,方便了不少。但是有一个小问题,当我在xcode输入import关键字的时候,没有自动联想补齐代码的功能,需要手工敲全了文件名,难以适应。
简单说就是这么几步:
选择Target -> Build Settings 菜单,找到\”User Header Search Paths\”设置项
新增一个值”${SRCROOT}”,并且选择\”Recursive\”,这样xcode就会在项目目录中递归搜索文件
自动补齐功能马上就好使了。
cmd + b编译下,就可以了