1. The ruby version that comes with the system is lower than 2.2, and the ruby version needs to be upgraded. However, it is recommended not to upgrade the existing ruby directly, but to install multiple versions of ruby through rvm, so install rvm first:
$ curl -L get.rvm.io | bash -s stable $ source ~ / .rvm / scripts / rvm
After the installation is complete, enter:
rvm -v
If the version information is displayed, it is already installed.
2. Install ruby
List installable ruby versions
rvm list known
Install a ruby version
rvm install 2.3
View installed ruby
rvm list
set ruby default version
rvm use 2.3 --default
Replace source:
$gem sources -l https://rubygems.org/ $gem sources --remove https://rubygems.org/ $gem sources -a http://rubygems-china.oss.aliyuncs.com
3. Install cocoapods
After Mac OS X EL Capitan upgrade , use the following command
sudo gem install -n /usr/local/bin cocoapods //Add one more sentence, perfect solution sudo xcode-select --switch /Applications/Xcode.app //update gem $sudo gem update --system pod setup
4. Using AFNetworking
search, view version
$ pod search AFNetworking
Switch to the project directory and create a Podfile
cd MyApp came Podfile
enter in the file
target 'MyApp' under 'AFNetworking', '~> 1.0'
save, exit.
Note: Podfile writing reference official website:
https://guides.cocoapods.org/syntax/podfile.html
Enter the command to install the class library into the project
pod install
You can see that there is an additional .xcworkspace file in the project directory, open it, and you can see that the class library has been imported into the project.