First, "CocoaPods learning", cocoapods

Source: Internet
Author: User
Tags install cocoapods

First, "CocoaPods learning", cocoapods

========================================================== ====================================

| Reprinted must indicate the blog address: http://www.cnblogs.com/devappnow |

| Respect originality and others' labor achievements. If you feel helpful to the reader, you can also encourage the blogger in any way (such as recommendations, comments, and emails ). |

========================================================== ====================================

I. What is CocoaPods?

Official Website Description: CocoaPods is the dependency manager for Swift and Objective-C Cocoa projects. it has almost ten thousand libraries and can help you scale your projects elegantly. (CocoaPods is an independent manager that provides management for Swift/Objective-C projects. It has tens of millions of third-party libraries, allowing you to manage your project structure elegantly)

My understanding: it makes it easier for programmers to manage third-party libraries. (It is common for ios projects to reference third-party libraries. Some large projects may reference more than 10 databases. manual management is inefficient because of such application requirements, so Cocoapods appears)

 

Ii. How to install

First,

1. Make sure that Brew is installed on your Mac.

2. Run the brew command to install ruby. (We need ruby commands to install cocoapods, so we need to install ruby)

Installation command: brew install ruby

3. Install cocoapods

Follow the instructions on the official website: Enter sudo gem install cocoapods on the terminal to install cocoapods successfully.

However, it seems that tian is not so easy to install successfully. (You can use the vpn proxy to download)

If you do not have a vpn, you can install it in tian even if you do not have a vpn.

Enter the following commands in sequence on the terminal:

1) gem sources -- remove the https://rubygems.org/

2) gem sources-a http://ruby.taobao.org/

The preceding steps allow you to re-specify an image address and access the image address in China to download and install cocoapods.

Check whether the image address has been modified successfully:

3) gem sources-l

After the modification is successful, you can run the cocoapods installation command to install cocoapods. Run the following command:

4) sudo gem install cocoapods

Successful.

3. How to Use cocoapods

Use xcode to create a project, such as CocoaPodsDemo. Use the terminal cd to enter the project and create a Podfile file (without a suffix and only a name ).

When editing the Podfile file, we recommend using vim to write and compile the pod file, note that the definition of the platform for ios should be in lower case and be enclosed in quotation marks (single-point quotation marks in English ).

Example of writing Podfile:

Platform: ios, '8. 0'

Pod 'afnetworking'

Pod 'sdwebimage'

The preceding three lines describe how to write Podfile. Specify the ios platform and ios version. Import the latest version of AFNetworking and the latest version of SDWebImage.

After the Podfile file is successfully written, run the command: pod install to start installation.

Wait a moment, cocoapods is helping you download your third-party library... Errors may occur, most of which are caused by incorrect format of your Podfile file.

After the execution is complete, you can see:

$ Pod install

Analyzing dependencies

Downloading dependencies

Installing AFNetworking (2.5.4)

Installing SDWebImage (3.7.2)

Generating Pods project

Integrating client project

[!] Please close any current Xcode sessions and use 'coapodsdemo. xcworkspace 'for this project from now on.

The above information indicates that the third-party library has been successfully imported into my CocoapodsDemo project. Follow the last sentence.

Open the CocoapodsDemo. xcworkspace project in our project, because Cocoapdos integrated the third library for us and merged the code to create the project.

In the Code, for example, to use SDWebImage, you only need to: # import <SDWebImageManager. h>

  

Open CocoapodsDemo. xcworkspace and check the new project structure created by cocoapods for us.

The project contains SDWebImageManager and AFNetworking.

Cocoapods can manage third-party libraries. we can update third-party libraries in this way:

1. Use the install command of pod to install the required third-party library.

2. If a third-party library has new updates on github, such as bug fixes and functional enhancements.

In this case, you can use another pod update command to obtain the latest database. cocoapods automatically integrates the latest code for the project and generates xcworkspace.

3. Use pod search xxxx to check whether such a library exists. For example (pod search SDWebImage)

Fan Wai:

How do I delete a third-party library that is no longer needed?

Similarly, edit the Podfile file, delete the third-party library you want to remove, save the Podfile file, and then execute the command pod install.

So far, we have learned how to use Cocoapods to easily import a third party. You do not need to copy and paste the file yourself. You need to debug and solve various errors.

 

========================================================== ====================================

| Reprinted must indicate the blog address: http://www.cnblogs.com/devappnow |

| Respect originality and others' labor achievements. If you feel helpful to the reader, you can also encourage the blogger in any way (such as recommendations, comments, and emails ). |

========================================================== ====================================

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.