1,官網下載安裝ruby
Mac直接在shell輸入下載安裝:
$ brew install ruby
若提示-bash: brew: command not found。
安裝homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1>、安裝rvm
RVM:Ruby Version Manager, Ruby版本管理器,包括Ruby的版本管理和Gem庫管理(gemset)
$ curl -L get.rvm.io | bash -s stable
2>、加載文件,測試是否安裝正常(按照提示操作)
$ source ~/.bashrc
$ source ~/.bash_profile
$ source ~/.profile
$ rvm -v
3>、獲取rvm列表,找到最新版本,安裝
$ rvm list known
4>、安裝ruby2.4
$ rvm install 2.4
安裝過程中可能遇到如下錯誤:
Error running 'requirements_osx_port_libs_install curl-ca-bundle automake libtool libyaml libffi libksba',showing last 15 lines of /Users/acewill/.rvm/log/1468253599_ruby-2.3.0/package_install_curl-ca-bundle_automake_libtool_libyaml_libffi_libksba.log
原因是需要安裝Homebrew, 參照stack overflow上的問題Installing RVM: “Requirements installation failed with status: 1.”
安裝Homebrew, 通過以下命令:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝完Homebrew,重新安裝ruby
$ rvm install 2.4
2、設置ruby的軟件源
$ gem sources -l #(查看當前ruby的源)
$ gem sources --remove https://rubygems.org/ #(移除當前ruby的源)
$ gem sources -a https://gems.ruby-china.org/ #(設置當前ruby的源,淘寶鏡像已經不能用了,可以用https://gems.ruby-china.org)
$ gem sources -l #(再次查看當前ruby的源)
如果Terminal輸出:
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
表示切換成功
3、設置gem為最新版本
如果gem太老,可以嘗試用如下命令升級gem:
$ gem update --system
升級成功后會提示: Latest version currently installed. Aborting.
如果出現
ERROR: While executing gem ... (OpenSSL::SSL::SSLError)
hostname "upyun.gems.ruby-china.org" does not match the server certificate
原因是之前用的ruby鏡像源是淘寶的,需要切換成https://gems.ruby-china.org/,在終端輸入
$ gem sources —remove https://ruby.taobao.org/
$ gem sources -a https://gems.ruby-china.org/
二。安裝cocoapods
1,在終端輸入命令
$sudo gem install cocoapods
2,pod search 第三方框架
$ pod search AFNetworking
按wq退出
如果出現 [!] Unable to find a pod with name, author, summary, or description matching AFNetworking
執行下面操作,刪除索引
$ rm ~/Library/Caches/CocoaPods/search_index.json
然后重新執行
$ pod search AFNetworking
3,項目中添加cocoapods:
1>需要在工程中根目錄,工程下面創建一個名字為Podfile的Empty文件
文件輸入
platform :ios, '8.0'
#use_frameworks!//個別需要用到它,比如reactiveCocoa
target 'WoVPNStore' do
pod 'AFNetworking', '~> 3.1.0'
pod 'JSONModel', '~> 1.3.0'
pod 'SDWebImage', '~> 3.8.1'
pod 'Masonry', '~> 1.0.1'
pod 'Reachability', '~> 3.2'
pod 'MJRefresh', '~> 3.1.12'
end
按這種格式輸入不會報下面這種錯誤:
還有一種寫法:
platform :ios, '8.0'
#use_frameworks!個別需要用到它,比如reactiveCocoa
def pods
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end
target 'MyApp' do
pods
end
之后關閉工程,打開終端,cd進入工程目錄,到有pod文件的那層。
$ pod install
即可,然后再次打開工程,打開.xcworkspace文件即可。
擴展在自己開源項目中使用cocoapods:
http://www.lxweimin.com/p/0e1d796b2a42
三。PrefixHeader.pch的使用:
1,新建pch文件,名字就是prefixHeader.pch
2,打開工程設置,building setting 搜索PrefixHeader,修改配置
根路徑:$(SRCROOT)/工程名/PrefixHeader.pch 比如:$(SRCROOT)/新聞APP/PrefixHeader.pch 注意不能打錯字母。
里面基本都是定義宏文件。