The latest CocoaPods installation tutorial and CocoaPods installation tutorial
What is CocoaPods?
Many third-party open-source libraries, such as JSONKit and AFNetWorking, are frequently used when you develop iOS applications. A class library may use other class libraries. to use it, you must download other class libraries. Other class libraries also use other class libraries ", this may be a special case. In short, it is very troublesome to manually download the required class libraries one by one. Another common situation is that the class libraries used in your project are updated. You must download the new version and add it to the project again, which is very troublesome. If you have any tools to solve these annoying problems, it will be "easy to understand ". So you need CocoaPods.
CocoaPods should be the most commonly used and famous class library management tool for iOS. The two annoying problems mentioned above can be completely solved through CocoaPods with only one line of commands, the premise is that you must set it correctly. Most famous open-source libraries support CocoaPods. Therefore, as iOS programmers, it is essential to master the use of CocoaPods.
How do I download and install CocoaPods?
Step 1: Install ruby
You cannot change the ruby source as soon as it comes up. Although the mac comes with ruby, the version is generally relatively low. If you do not update it, the version dependency problem will occur.
Rvm is used to manage ruby, which allows coexistence of multiple ruby. RVM: Ruby Version Manager, which includes Ruby Version management and Gem library management.
Run the following command to install rvm:
$ curl -L get.rvm.io | bash -s stable $ source ~/.bashrc $ source ~/.bash_profile
After the installation is complete, run the following command to check whether the rvm is successfully installed:
rvm -v
Then you can use rvm to install or upgrade Ruby. First, check the Ruby version:
MacBook-Air:~ xxxxx$ rvm list known# MRI Rubies[ruby-]1.8.6[-p420][ruby-]1.8.7[-head] # security released on head[ruby-]1.9.1[-p431][ruby-]1.9.2[-p330][ruby-]1.9.3[-p551][ruby-]2.0.0[-p648][ruby-]2.1[.10][ruby-]2.2[.6][ruby-]2.3[.3][ruby-]2.4[.0]ruby-head
You can see the latest version and run the following command to install it:
rvm install 2.4
After installation, set it to the default version:
rvm use 2.4 --default
Step 2: Change the ruby Source
After upgrading the latest ruby, you can change the ruby source.
First, remove the source of the original shard:
gem sources --remove https://rubygems.org/
Then add the latest sources officially maintained by ruby in China:
gem sources -a https://gems.ruby-china.org/
Then make sure that there is only one source:
MacBook-Pro:~ xxxxx$ gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.org/
Then update ruby components:
sudo gem update --system
The above are the most authoritative steps on the Internet. If you do not have any problems, it will be okay.
The following error is reported during update:
ERROR: While executing gem ... (OpenSSL::SSL::SSLError) hostname "upyun.gems.ruby-china.org" does not match the server certificate
Finally, various attempts are made. Use the following method to continue. If you have the same situation, try the following.
Remove the newly added source, add another source, and remove the last slash of the original address:
gem sources --remove https://gems.ruby-china.org/ gem sources -a https://gems.ruby-china.org
Step 3: Install CocoaPods
sudo gem install -n /usr/local/bin cocoapods sudo xcode-select --switch /Applications/Xcode.app
Enter the following command on the terminal to complete installation:
pod setup
This step takes some time, so wait patiently.
If the installation fails ,~ /. Cocoapods is empty, and you need to re-setup
pod repo remove master pod setup
If Setup completed appears, the installation is complete.
Step 4: Create a Podfile
1. Create a project and cd it to the project directory.
2. Create a Podfile
vim Podfile
3. Press I to enter the editing status.
4. Enter a third party and version, for example:
Platform: ios, '8. 0' target 'Your project name 'do pod' class library name' end
To determine whether the third-party open-source Class Library supports CocoaPods, you can use the CocoaPods search function to verify. Enter:
$ Pod search Class Library name
5. After editing, Press esc and then enter: wq (In English input) to save and exit.
6. Import a third-party library
pod install
7. Open the project file suffixed with. xcworkspace and perform subsequent encoding operations in this file.
8. When a third-party library is required, import the header file, for example: # import <AFNetworking. h>