iOS in-depth learning (third-party resource management using Cocoapods)

Source: Internet
Author: User
Tags wordpress blog

A year ago in the outsourcing company, marvel at the strength of cocoa pods, also let me have a lot of confusing place. Previously wrote a cocoa pods use of the blog, detailed list of UNIX terminal commands to build the environment, published in Sina SAE built WordPress blog platform, but because there is no renewal, now can not find.

Nearly half a year in the new company, marvel at the boss to deal with the project dependencies, my boss is mainly on the iOS platform Xcode tool workspace, Project, Target and a variety of static library relationship between the understanding of the more thorough, so he is very good at this aspect of operation. In fact, with the eldest brother learning this aspect of things, the basic can meet the needs of project resource management, but why I have to reorganize cocoa Pods, summed up the cocoa Pods environment of the blog? I think the main points are as follows:

(1) See a lot of iOS blog tutorial, the basic initial step is to have cocoa pods environment;

(2) Cocoa pods is indeed a convenient tool, especially in the agile development of multiple projects, a tool reuse, a lot of time saving;

(3) can update the open Source Library code on GitHub in time, just change the version number of the corresponding open source library in the Podfile file.

I. Introduction of COCOA Pods

Cocoa Pods is a tool responsible for managing third-party resources in iOS projects, and its project source code is managed on GitHub, thanks to the ongoing maintenance of the active GitHub developer community, which has been actively updated since the launch of the project in August 2011. Developing iOS projects inevitably uses third-party open source libraries, and the advent of cocoapods allows us to save time setting up and updating third-party open source libraries.

After we have the Cocoapods tool, we just need to put the third-party open Source Library into a file named Podfile, and then execute the $pod install command at the command line, Cocoapods will automatically download the source code of these third-party repositories, and set the system dependencies and compilation parameters for the current project to be responsive.

Second, the installation of Cocoa pods

(1) Installation

The way you install it is simple, with Ruby on your Mac, so you can install it with Ruby's Gem command. Open the Mac Terminal tool and run the following command at the terminal,

?
12 [sudo] gem install cocoapodspod setup

Note that the above [sudo] can be omitted, both of these steps are the process of making a network request, so a certain amount of waiting time is required.

(2) Update

If we modify the Podfile file, then we need to update the Cocoapods, using the following Ruby's Gem command to update,

?
1 [sudo] gem update cocoapods

(3) Find a third-party library

You can search for a third-party library using pod Search + Lib_name, as shown in the following command

?
1 sudo pod search sdwebImage

Description: Sdwebimage is an open source library for image caching and is an extension of the Uiimageview class.

Third, the use of Cocoa pods

Now I create a new project under the Desktop/develop folder, refer to a tutorial in Cocoachina, is a full weather app, the project name is Simpleweather, then the next operation using Cocoa Pods,

(1) Enter the folder where the project Simpleweather.project is located, enter the following command at the terminal,

?
1 cd Desktop/develop/SimpleWeather

(2) In this directory, new Podfile via Vim

?
1 vim Podfile

(3) through I (insert mode), insert the following statement,

?
123456 platform :ios, ‘7.0‘   pod ‘Mantle‘ pod ‘LBBlurredImage‘ pod ‘TSMessages‘pod ‘ReactiveCocoa‘

This specifies the iOS version of the third-party resources, the open source Library mainly includes: Mantle, Lbblurredimage, tsmessages, Reactivecocoa, these are not important, here is just a demonstration.

After the input is complete, exit vim and save, ESC and then enter: Wq, which means write and exit.

(4) in terminal input $pod install,

?
1 pod install

The initialization pod is also a network request download process, wait a period of time, if the input resource name is not a problem, then over a period of time will be in the terminal to initialize the successful prompt.

Iv. writing the project code through workspace

Enter the project folder, you can see a suffix name does not. workspace file, double-click Open. From now on, we open the workspace file by Simpleweather.xcworkspace managing the project, writing the code instead of the previous simpleweather.xproj, the file structure of the Xcode project is shown,

The first arrow refers to the Simpleweather project, and the second arrow is the project that pods helps us build, which manages the required library, and the third arrow points to the third-party open Source Library specified in Podfile.

It is also important to note that every time we modify podfile this file, be sure to execute the $pod install command in the folder where the project is located, and also perform $pod update to update the class library.

Summarize:

Here is a summary of my development process, there are a lot of details not taken into account, I will be based on the problems I encountered and constantly update this blog. When working in the home company encountered some cocoapods update when the need for the highest permissions, I try to reproduce in the back, to help meet the problem of friends to solve the problem.

iOS in-depth learning (third-party resource management using Cocoapods)

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.