Cocoapods Installation and use

Source: Internet
Author: User

Cocoapods is a tool for managing third-party open source code in iOS projects. Using Cocoapods can save us the time to set up and update third-party open source libraries. The following two sections describe how to install and use Cocoapods.

First, install the Cocoapods

First use the following command to upgrade the Ruby version:

?
1 gem update --system

After waiting for the update to complete, then download the installation Cocoapods by using the Gem command:

?
1 gem installcocoapods

After the installation is complete, call the following command to set the Cocoapods:

?
1 pod setup

After executing the above command, the installation is successful! The following describes how to use Cocoapods.

Second, the use of cocoapods

Open the terminal and use the CD command to navigate to the project root path where you want to use Cocoapods. Such as:

?
1 cd/Users/username/Documents/Projects/Demo

Consider which libraries you need to reference in your project, and then, using the Search command to find information about the library, if you need to add Jsonkit, you can do the following:

?
1 pod search JSONKit

When the command executes, it gets the following result:

?
123456 -> JSONKit (1.5pre)   A Very High Performance Objective-C JSON Library.   pod ‘JSONKit‘, ‘~> 1.5pre‘   - Homepage: https://github.com/johnezang/JSONKit   - Source:   https://github.com/johnezang/JSONKit.git   - Versions: 1.5pre, 1.4 [master repo]

One of the pod ' Jsonkit ', ' ~> 1.5pre ' is the information that will be written to Podfile later. If you already know this information, you can omit this step directly. Proceed directly to the following steps.

Once you have the necessary library information, you now need to build the Podfile file in your project. Use the following command:

?
1 touchPodfile

Then edit the Podfile file with the following command:

?
1 open-e Podfile

Enter the following in the popup editing screen:

?
123 platform :iospod ‘JSONKit‘, ‘~> 1.5pre‘

Then invoke the following command to initialize:

?
1 pod install

After running, the original project directory will have some extra files.

More *.xcworkspace pods and other files. This is the project management file that pod generates, open the Libdemo.xcworkspace project file, and see in Xcode the directory structure:

One thing to note here is that if you do not call the Create Podfile command, you call the pod Install command directly. You will be prompted "

[!] No ' podfile ' found in the current working directory. "

If you added a new library to Podfile, you can use the following command to update it:

?
1 pod update

Now that all of your third-party libraries have been downloaded and set up with compilation parameters and dependencies, you just have to remember the following 2 points:

1. Use the. xcworkspace file generated by Cocoapods to open the project instead of the previous. xcodeproj file.
2, each time you change the Podfile file, you need to re-execute the pod install or pod Update command.

Cocoapods Installation and use

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.