Installation process for the latest version of CocoaPods

Source: Internet
Author: User
Tags install cocoapods

First, what is CocoaPods1, why need cocoapods

The use of third-party open source libraries, such as Sbjson, afnetworking, reachability and so on, is unavoidable when developing iOS. The use of these libraries usually requires:

    • Download source code and introduce engineering
    • To add the framework that the Open Source Library uses to the project
    • Resolves issues such as dependencies between open source and open source libraries and open source libraries and projects, and checking for overlapping framework additions
    • If the Open source Library is updated, you also need to delete the Open Source library used in the project, re-execute the previous three steps, suddenly the head is big ...

Since the cocoapods, these complex work will no longer need our pro-strength, just need us to do a small amount of configuration work, Cocoapods will do everything for us!

2. What is Cocoapods

Cocoapods is a tool to help us manage third-party dependent libraries. It solves the dependencies between libraries and libraries, downloads the source code of the library, and connects these third-party libraries to our project by creating a Xcode workspace for us to develop and use.

The purpose of using cocoapods is to enable us to automate, centralize, and intuitively manage third-party open source libraries.

Second, installation Cocoapods

1. Remove the existing Ruby default source

$gem sources--remove https://rubygems.org/

2. Use the new source

$gem sources-a https://gems.ruby-china.org

3. Verify that the Xinyuan is replaced successfully

$gem sources-l

1. Installation

Cocoapods is implemented in Ruby and requires a ruby environment to use it first. Fortunately, the OS X system is already running Ruby by default, so we just need to execute the following command:

(1) $sudo gem install cocoapods Note: After upgrading OS X EL Capitan, the Apple system changes to $sudo gem install-n/usr/local/bin cocoapods

Cocoapods is installed in the form of a Ruby gem package. During the execution of the installation, you may be asked if we are updating rake and entering Y. This is because the Rake gem package will be checked more finely during installation, and if a new version is available, the option just now appears.

(2) $pod Setup

If there is no error, it means that all the installation is successful!

(3) Gem version too old

GEM is the standard package for managing Ruby libraries and programs, and if its version is too low it can cause installation to fail, the solution is to upgrade the Gem and execute the following commands:

$ sudo gem update--system

Note: RVM and gems distinguish between various concepts related to Ruby (RVM, Gem, Bundle, Rake, rails..._ Blog Park

Http://www.cnblogs.com/ziyouchutuwenwu/p/4099690.html

Third, the use of cocoapods

If everything goes well, then you can experience the magic of Cocoapods, which takes the following steps:

To demonstrate this process, I created a project called Cocoapodstest.

1. Create Podfile

Cocoapods everything starts with a file named Podfile, we need to create this file first. Personal habits using the command line, I will do this:

    1. $ cd/users/wangzz/desktop/cocoapodstest
    2. $pod Search Third Party
    3. $ Touch Podfile
    4. First go to the project root directory, create a blank podfile file, create a complete directory structure such as:

2. Edit Podfile

As needed, we can write the required third-party libraries in the Podfile file, for example, Sbjson, Afnetworking, reachability three libraries, my podfile content is as follows:

$vim Podfile

Write the following and save the tip: (the terminal vim file can be edited by I, ESC exits edit: Wq can be saved exit)

    1. Platform:ios, ' 7.0 '
    2. Pod ' afnetworking ', ' ~> 2.0 '
    3. Pod ' Sbjson ', ' ~> 4.0.0 '
    4. End

. Import third-party libraries

$pod Install

Take a look at the changes in the engineering root directory, such as:

As you can see, there are three more things under the project's root directory: Cocoapodstest.xcworkspace, podfile.lock files, and pods directories.

(PS: Limited space, Podfile.lock file will be placed in the next article of the series, please pay attention to. )

Take a look at the last line of content that was printed just after the pod install command was executed:

      1. [!] From "On" Use ' cocoapodstest. Xcworkspace '.

Tip us from now on, we need to use the Cocoapodstest.xcworkspace file to develop.

For changes in engineering, there are several points to note:

    • Third-party libraries are compiled into static libraries for our real project use

Cocoapods will create a project called Pods with all third-party libraries as Target, and the project will be placed in the newly generated pods directory. The entire third-party library project will generate a static library called LIBPODS.A to provide our own Cocoapodstest engineering use.

    • Our project and the third party Libraries project will be managed by a newly generated workspace

To facilitate our intuitive management of engineering and third-party libraries, cocoapodstest engineering and Pods engineering will be organized and managed in the form of workspace, the Cocoapodstest.xcworkspace file we have just seen.

The original project settings have been changed, this time we directly open the original project files to compile will be error, can only use the newly generated workspace for project management.

Installation process for the latest version of 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.