1、Ruby環境搭建
a、查看下當前ruby版本:打開終端輸入 ruby -v,
*** CURRENT SOURCES ***
https://ruby.taobao.org/
如為上方內容,則無需再次配置,若不是,則需更新ruby
b、更新ruby
終端輸入如下命令
gem sources --remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/
gem sources -l (用來檢查使用替換鏡像位置成功)
顯示
*** CURRENT SOURCES ***
https://ruby.taobao.org/
則成功
2、下載安裝CocoaPods
終端輸入:sudo gem install cocoapods
CHANGELOG:
## 0.32.1
##### Bug Fixes
* Fixed the Podfile `default_subspec` attribute in nested subspecs.
[Fabio Pelosin][irrationalfab]
\ [#2050](https://github.com/CocoaPods/CocoaPods/issues/2050)
Successfully installed cocoapods-0.32.1
Installing ri documentation for cocoapods-0.32.1
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block
Done installing documentation for cocoapods after 10 seconds
1 gem installed
安裝成功
3、使用CocoaPods
a 新建一個項目,名字PodTest
b 終端中,cd到項目總目錄(注意:包含PodTest文件夾、PodTest.xcodeproj、PodTestTest的那個總目錄)
cd /Users/lucky/Desktop/PodTest
c 建立Podfile(配置文件)
接著上一步,終端輸入 vim Podfile
鍵盤輸入 i,進入編輯模式,輸入
platform :ios, '7.0'
target :Demo1 do
pod 'MBProgressHUD', '~> 0.9.1'
pod 'AFNetworking', '~> 2.5.4'
pod 'MJRefresh', '~> 2.3.2'
end
target :Demo2 do
pod 'MBProgressHUD', '~> 0.9.1'
pod 'AFNetworking', '~> 2.5.4'
pod 'MJRefresh', '~> 2.3.2'
end
注:版本號可不寫
然后按Esc,并且輸入“ :”號進入vim命令模式,然后在冒號后邊輸入wq
注意:鍵盤輸入 :后,才能輸入wq。回車后發現PodTest項目總目錄中多一個Podfile文件
激動人心的時刻到了:確定終端cd到項目總目錄,然后輸入 pod install,等待一會,大約3分鐘。
查看項目根目錄:
注意:現在打開項目不是點擊 PodTest.xodeproj了,而是點擊 PodTest.xcworkspace