CocoaPods能够方便地经过Mac自带的RubyGems安装。ios
打开Mac电脑自带的终端,而后按照如下操做便可:swift
首先查看ruby当前源 vim
$ gem sources -l *** CURRENT SOURCES *** https://rubygems.org/
移除ruby当前源ruby
$ gem sources --remove https://rubygems.org/
替换国内最新镜像源(淘宝的Ruby镜像已经不更新了,https://gems.ruby-china.org域名更新为https://gems.ruby-china.com)ide
$ gem sources -a https://gems.ruby-china.com/
再次查看ui
$ gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.org
若是使用 $ gem update --system spa
会报错误 debug
ERROR: While executing gem ... (Gem::FilePermissionError)code
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directoryorm
这时使用
$ sudo gem update --system
升级成功后会提示
RubyGems system software updated
若是使用 $ sudo gem install cocoapods
报错误
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory
那就使用
$ sudo gem install -n /usr/local/bin cocoapods
而后执行pod setup (ps:这个执行很慢,耐心等待...... pod setup在执行时,会输出Setting up CocoaPods master repo,而后会卡一下子。这步实际上是 Cocoapods 将它的信息下载到 ~/.cocoapods目录下,你能够command+n
新建一个终端窗口,执行cd ~/.cocoapods/
进入到该文件夹下,而后du -sh *
查看文件大小,这个目录最终大小是900多M。出现Setup
completed 的时候说明已经完成了
$ pod setup
①首先搜索须要的三方库 AFNetworking,会出现符合条件的搜索结果
$ pod search AFNetworking
②在工程中建立Podfile文件,输入终端命令进入到工程目录下,而后建立Podfile文件
$ cd /Users/Desktop/YourAPPName $ vim Podfile
③进入界面后,输入
platform :ios, '8.0' target 'YourApp' do pod 'AFNetworking', '~> 3.1.0' end
④把三方库下载到工程中
$ pod install
注:若是是在swift的工程中引入三方库,pod install 可能出现下面错误,处理办法
[!] The `GWeather [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-GWeather/Pods-GWeather.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target.
找到【Project/Target】-->【Your Project Name】-->【Buid Settings】
搜索‘ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES’,选择“other”,输入 $(inherited)