CocoaPods: Managing various third-party open Source Library associations in the OBJECTIVE-C program

Source: Internet
Author: User
Tags install cocoapods

In our iOS program, we often use multiple third-party open source libraries, usually by downloading the latest version of the open Source Library and then dragging it into the project.

However, once the number of third-party open source libraries is more, version management is very troublesome. Is there any way to simplify the management of third-party libraries? Yes! When I was using the third-party library of Sdwebimage, I was learning how to show progress, and I saw someone mention using Cocoapods (http://cocoapods.org/, FQ) to manage the third-party open Source Library.

CocoaPods is a great way to manage the various third-party open source libraries in the OBJECTIVE-C program, as long as the CocoaPods is installed and a podfile text is created in the root of your program, which shows which packages to use, CocoaPods will help you with the dependencies of all the packages.

Now let's learn how to use the Cocoapods.

Installation

CocoaPods is a Ruby Gem, so as long as the installation instructions are issued in Terminal:

12 gem install cocoapodspod setup

Note: You may feel unresponsive when executing the code, it takes time, and wait patiently.

So it's installed, check to see if it's installed. Search for a third-party open Source Library:

1 pod search SDWebImage

The results are as follows:

There is no report error or anything else stating that the Cocoapods installation was successful.

OK, let's see how we can use it.

Use

For example, if you want to use the Sdwebimage Open Source Library, you can use the command: Pod search sdwebimage to search for the current number of sdwebimage versions and information about each version. Then select the version you want and add it to the Podfile file.

There are two ways to add an open source library to a Podfile file:

Method One (manually build the Podfile document):

    • You create a new text document named Podfile in the root directory of your project;
    • Then copy the text inside the Red box (pod ' sdwebimage ', ' ~> 3.4 ');
    • Save, and then remove the suffix name of the text document (there will be a suffix error, pro-test).
Method Two (command-line build Podfile document):
    • First locate the root of your project (because the document is to be built here);
    • Then edit the Podfile document (Podfile exists then edit, no new), will be in the red box in the text (pod ' sdwebimage ', ' ~> 3.4 ') copied into;
    • Save.
The command line looks like this:
12 cd ‘你的工程根目录‘#不要引号 ,打开你的根目录vi Podfile                #打开并开始编辑

As shown in the following:

Press ESC to exit edit after editing, and then enter ': Wq ' to save and exit. Now you can install dependencies in your project:
1 pod install

Tips: If you reference a library that is large and does not need all the files, you can write:

1 pod ‘Nimbus/Core‘

After the installation is successful, your project and the wood will produce a file like this:

Be sure to use this file to open your project in the future.

Create a pod (from Cocoapods official website: http://cocoapods.org) Sometimes cocoapods does not have the pod resources you need, but fortunately, you can easily create one:
Pod Spec Create peanut edit Peanut.podspec pod spec Lint Peanut.podspec
When you do, please create a ticket and upload the pod. You can also fork Thecocoapods specs GitHub repository and send a pull request. We really love contributions! Add: How to use the updated pod:http://www.cnblogs.com/procoder/archive/2013/01/15/in Cocoapods How-to-get-updated-version-of-pods-on-cocoapods.html

CocoaPods: Managing various third-party open Source Library associations in the OBJECTIVE-C program

Related Article

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.