iOS Development 61-cocoapods installation and use
What is Cocoapods
Cocoapods is a third Class library management tool under OS X and iOS, and through the Cocoapods tool we can add a dependency library called "Pods" to the project, which must be supported by Cocoapods itself, and can easily manage its version.
the meaning of cocoapods is embodied in two aspects.
First, it can automatically complete a variety of configurations for us when introducing a Third-party library, including configuring the compile phase, connector options, and even-FNO-OBJC-ARC configurations in the ARC environment. Second, using cocoapods makes it easy to find new Third-party libraries, which are more "standard" than those found on the web, so that we can find a really useful class library.
core components of Cocoapods
The Cocoapods is written in Ruby and is divided into several gem packages.
The cocoapods of the most important packages in parsing execution are: Cocoapods/cocoapods, Cocoapods/core, and Cocoapods/xcodeproj.
Cocoapods/cocoapod: This is a user-oriented component that will be activated whenever a pod command is executed. It includes all the functionality of the utility cocoapods and can also invoke other gem packages to perform the task.
The Cocoapods/core:core gem provides processing of cocoapods-related files (mainly podfile and podspecs).
Podfile: This file is used to configure the Third-party libraries needed for the project, which can be highly customizable. In this article, we mainly do the action here.
Podspec: This file describes how a library will be added to the project. The. podspec file identifies the source files, dependent libraries, compilation options, and other third-party libraries needed for the Third-party library.
Cocoapods/xcodeproj: This package is responsible for working with engineering files, which create and modify. xcodeproj files and. xcworkspace files. It can also be used as a stand-alone package, and you can consider using cocoapods/xcodeproj when you want to write a script that modifies the project file.
Cocoapods Installation Steps
1. Upgrade Ruby Environment
Terminal input: $gem update--system
This will appear
Error:while Executing gem ... (Gem::filepermissionerror)
You are don ' t have write permissions for the/library/ruby/gems/2.0.0 directory.
zijingmacbook-pro:~ shiyunlei$ sudo gem update-system
This is because you don't have the authority to update Ruby.
This time you can use at the end: $sudo gem Update-system to upgrade
2, update the mirror Web site
When installing Cocoapods we want to visit cocoapods.org, the site may be wall, so the download installation may be turtle speed, fortunately we can use Ruby mirror to access the site, as follows:
1. Gem Sources--removehttps://rubygems.org/
2. Gem Sources-a https://gems.ruby-china.org/
You can use the following command to see if mirroring has been replaced successfully
$ gem sources-l
3, install Cocoapods, in the terminal input command
$sudo Gem Install Cocoapods
This time will prompt you to enter the password, note: In the terminal input password does not have the prompt, the cursor also does not move, must notice
Start installation, this process may take a long time
Error at this time:
Unable to resolve Dependencies:cocoapods requires Cocoapods-core
Update the Gem and start again
sudo gem update--system
sudo gem install Cocoapods
Appears Operation not permitted-/usr/bin/xcodeproj
Use the following command to resolve
sudo gem install-n/usr/local/bin cocoapods
4. Search the class library name using the search command:
$pod Search Afnetworking
If cocoapods support, it will output all the class library versions and information found, as well as the configuration in Podfile, and the terminal will return information.
-> afnetworking (2.3.1)
A delightful IOS and OS X networking framework.
Pod ' afnetworking ', ' ~> 2.3.1 ' (this statement is a command that needs to be entered when editing Podfile, that is, how to install instructions to download the related class library)
5, need to create a podfile file in the project,
To use the command:
$CD/users/xx/desktop/cocoapodssample (into the engineering directory, behind the CD is the project path)
$ Touch Podfile (create Podfile file)
Then use Vim to edit the Podfile file, using the command:
$ vim Podfile
Then press the "I" key on the keyboard to become the following state, at which point the Podfile file can be edited:
$platform: iOS, ' 7.0 '
$ Pod ' afnetworking ', ' ~> 2.3.1 '
Press ESC when the edit is complete,
Then press ":", this time enter Wq, click Enter, save and exit.
Then install the corresponding third party library in the Terminal input command
$pod Install
Because this process needs to download the corresponding class library, so time and speed related.
This time you'll see. Open engineering needs to be opened from type to project name. xcworkspace File Open