When we develop mobile applications, we generally use third-party tools, and because of the wide variety of third-party libraries, we manage the project in a relatively cumbersome way, so at this point we need a package management tool, in iOS development, we use the most is cocoapods.
Cocoa is an API for developing iOS touch-class devices, which is developed under OS X Apple's Api,cocoa touch. For example, in developing iOS, we often need to create a new class that is created with the Cocoa Touch class. In this blog, we will discuss the installation and use of the package management tool Cocoapods.
Installation of "one" cocoapods
(1) Cocoapods's official website is: https://cocoapods.org/. If your computer already has a ruby development environment installed, you can install it directly in the terminal (Terminal) using the following command:
sudo gem install Cocoapods
(2) If your computer does not have a Ruby environment installed, take a look at the following steps: First install RVM, the Ruby virtual machine, similar to the JVM, execute the following command:
Curl-l Https://get.rvm.io | Bash-s Stable
(3) Reload the RVM, or re-open the terminal terminal can also:
SOURCE ~/.RVM/SCRIPTS/RVM
(4) Check that the RVM is installed successfully and view the RVM version:
Rvm-v
(5) Then use RVM to install the Ruby environment:
RVM Install 2.0.0
(6) To view the version of Ruby:
Ruby-v
(7) When installing Ruby, the gem is installed by default and we can also view the gem version:
Ruby-v
(8) The following starts to install Cocoapods, because there is a wall, so we want to modify the image of Ruby, it happens that a treasure provides this image: First remove the original image:
Gem Sources--remove https://rubygems.org/
(9) Then add a new Image:
Gem Sources-a http://ruby.taobao.org/
(10) To view the current Ruby image, if the display is taobao.org:
Gem Sources-l
(11) This is the final step, install the Cocoapods: Wait a moment to it;
sudo gem install Cocoapods
The use of "two" cocoapods
(1) First set up an iOS project, I take swift language as an example, I named Cocoapodsdemo. The current directory structure is as follows:
。
(2) Enter the root directory of this project under the terminal and use Vim to create a podfile file,
.
(3) then enter the following code in Podfile, where I take afnetworking as an example: Save exit.
。
(4) Then the following command is still executed at the root of the project: results
Pod Install
。
(5) Then prompt in the terminal to use ***.xcworkspace to open the project, so we close the previous Xcode, to the project root directory, Open the Cocoapodsdemo.xcworkspace and then open the project, and the project structure has been turned into this:
。
At this point, a third-party library has been imported into the project and can be referenced in development. In the future we can use Cocoapods to manage our library, is not very convenient?
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Installation and use of iOS package management tool Cocoapods