Installation and use of iOS package management tool Cocoapods

Source: Internet
Author: User
Tags install cocoapods

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.