I. Introduction of COCOA Pods
Cocoa Pods is a tool responsible for managing third-party resources in iOS projects, and its project source code is managed on GitHub, thanks to the ongoing maintenance of the active GitHub developer community, which has been actively updated since the launch of the project in August 2011. Developing iOS projects inevitably uses third-party open source libraries, and the advent of cocoapods allows us to save time setting up and updating third-party open source libraries.
After we have the Cocoapods tool, we just need to put the third-party open Source Library into a file named Podfile, and then execute the $pod install command at the command line, Cocoapods will automatically download the source code of these third-party repositories, and set the system dependencies and compilation parameters for the current project to be responsive.
Second, the installation of Cocoa pods
(1) Installation
The way you install it is simple, with Ruby on your Mac, so you can install it with Ruby's Gem command. Open the Mac Terminal tool and run the following command at the terminal,
1 [sudo] gem install cocoapods 2 pod Setup
Note that the above [sudo] can be omitted, both of these steps are the process of making a network request, so a certain amount of waiting time is required.
(2) Update
If we modify the Podfile file, then we need to update the Cocoapods, using the following Ruby's Gem command to update,
1 [sudo] gem update cocoapods
(3) Find a third-party library
You can search for a third-party library using pod Search + Lib_name, as shown in the following command
sudo pod search sdwebimage
Description: Sdwebimage is an open source library for image caching and is an extension of the Uiimageview class.
Third, the use of Cocoa pods
Now I create a new project under the Desktop/develop folder, refer to a tutorial in Cocoachina, is a full weather app, the project name is Simpleweather, then the next operation using Cocoa Pods,
(1) Enter the folder where the project Simpleweather.project is located, enter the following command at the terminal,
1 cd Desktop/develop/simpleweather
(2) In this directory, new Podfile via Vim
1 Vim Podfile
(3) through I (insert mode), insert the following statement,
1 ' 7.0 ' 2 3 ' Mantle ' 4 ' Lbblurredimage ' 5 ' tsmessages ' 6 ' Reactivecocoa '
This specifies the iOS version of the third-party resources, the open source Library mainly includes: Mantle, Lbblurredimage, tsmessages, Reactivecocoa, these are not important, here is just a demonstration.
After the input is complete, exit vim and save, ESC and then enter: Wq, which means write and exit.
(4) in terminal input $pod install,
1 pod Install
The initialization pod is also a network request download process, wait a period of time, if the input resource name is not a problem, then over a period of time will be in the terminal to initialize the successful prompt.
Iv. writing the project code through workspace
Enter the project folder, you can see a suffix name does not. workspace file, double-click Open. From now on, we open the workspace file by Simpleweather.xcworkspace managing the project, writing the code instead of the previous simpleweather.xproj, the file structure of the Xcode project is shown,
The first arrow refers to the Simpleweather project, and the second arrow is the project that pods helps us build, which manages the required library, and the third arrow points to the third-party open Source Library specified in Podfile.
It is also important to note that every time we modify podfile this file, be sure to execute the $pod install command in the folder where the project is located, and also perform $pod update to update the class library.
iOS development uses cocoapods for third-party resource management