Many third-party open-source libraries, such as AFNetworking, FMDB, and JSONKit, are often used in iOS development. Using CocoaPods, you can easily manage the class libraries used in the project, including automatic download configuration and updates.
First, you need to download and install CocoaPods. The system requires a ruby environment. At least OS X 10.9 will bring your own ruby environment (Python also comes with it ), run the "ruby-v" command to view the current ruby version.
The configuration process is as follows:
If you are not at ease, check the ruby environment first. It is said that due to the influence of GFW, most Ruby images are directed to taobao (in fact, they were not set when they were used for the first time last month, for stability, run the following command:
Gem sources -- remove https://rubygems.org/
Gem sources-a http://ruby.taobao.org/
Gem sources-l (used to check whether the image is successfully replaced)
Run the following command:
Sudo gem install cocoapods
After the installation is complete, you can use it. to download and use a third-party class library through CocoaPods, first check whether CocoaPods supports the target class library. Although most of them are supported, check whether CocoaPods is healthier.
For example, check whether AFNetworking is supported and run the "pod search AFNetworking" command to view the relevant information.
The following example shows how to use CocoaPods to manage third-party class libraries in a project named "DemoMap", enter the project directory, and create a Podfile (CocoaPods configuration file)
Run the following two commands:
Cd/hou/DemoMap
Vim Podfile
Press "I" to enter the editing mode, and enter the following information in Podfile (according to the prompt information in the class library on GitHub ):
Platform: ios, '7. 0'
Pod "AFNetworking", "~> 2.0"
Press ESC to exit the editing mode and enter wq to save the operation.
Enter pod install to start automatic download and configuration. Then open the file with the. xcworkspace extension for the project.
The third-party dependent libraries downloaded are stored in the Pods folder.
After opening, you can find that AFNetworking is automatically introduced in the project.
You can directly use the header file after referencing it in the project. If the class library is updated, you can update the configuration file in step 1 and then execute "pod update.
In addition, after downloading an open-source project on GitHub, if CocoaPods is used for this project, you can directly cd it to the directory where the project is located, execute "pod install" to download and configure all the third-party dependent libraries used at a time, which is much easier to import than downloading one by one.