iOS crazy detailed cocoapods do iOS package dependency management

Source: Internet
Author: User

As each language develops to a single stage, a corresponding dependency management tool appears, or a central code repository. Like what

Java:maven,ivy
Ruby:gems
Python:pip, Easy_install
NODEJS:NPM

As iOS developers have grown, the industry has also come up with a dependency management tool for iOS programs called CocoaPods.

Cocoapods Introduction

Cocoapods is a tool for managing third-party open source code in iOS projects. The source code for the Cocoapods project is managed on GitHub. The project began on August 12, 2011, and after more than a year of development, it has now been submitted more than 1000 times and has continued to remain active and updated. 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.

Take my previous development of the chalk Web iphone Client For example, which uses 14 third-party open source libraries. Before using cocoapods, I need to:

copy the relevant files from these third-party open source libraries to the project, or to Git's submodule, and these open source libraries often need to rely on some framework of the system, I need to manually add these frameworks one by one to the project dependencies, For example, the ASI network Library needs to add the following framework:cfnetwork, SystemConfiguration, Mobilecoreservices, Coregraphics and zlib.
For regexkitlite This regular expression library, I also need to set the compilation parameters of-licucore
Manually manage updates for these dependent packages.

These physical activities, though simple, have no technical content and waste time. After using Cocoapods, I only need to put the third-party open Source Library in a file named Podfile, and then execute the pod install. Cocoapods will automatically download the source code of these third-party open source libraries and set up the corresponding system dependencies and compilation parameters for my project.

Introduction to installation and use of Cocoapodsinstallation

The installation is exceptionally simple, with Ruby on your Mac, and you can download the installation using Ruby's GEM command:

[HTML] view plaincopy$ gem Install cocoapods
$ pod Setup

Use

When using, you need to create a new file named Podfile, in the following format, the dependent library name is listed in the file.

[HTML] view plaincopyPlatform:ios
pod ' jsonkit ', ' ~> 1.4 '
pod ' reachability ', ' ~> 3.0.0 '
pod ' asihttprequest '
pod ' regexkitlite '

Then you put the edited Podfile file in your project root directory and execute the following command:
[HTML] view plaincopyCD "Your Project Home"
pod Install

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:

use the . xcworkspace file generated by Cocoapods to open the project instead of the previous . xcodeproj file.
Each time you change the Podfile file, you need to re-execute the pod install command.
find a third-party library

If you don't know if there are any libraries you want in the Cocoapods managed library, then you can find them through the pod Search command, and here are all the available libraries I found with pod search JSON:

[HTML] view plaincopy$ pod Search JSON
  
  
-> anyjson (0.0.1)
Encode/decode JSON by any means possible.
-Homepage:https://github.com/mattt/anyjson
-Source:https://github.com/mattt/anyjson.git
-versions:0.0.1 [master repo]
  
  
-> jsonkit (1.5pre)
A Very High performance objective-c JSON Library.
-Homepage:https://github.com/johnezang/jsonkit
-Source:git://github.com/johnezang/jsonkit.git
-Versions:1.5pre, 1.4 [master repo]
  
  
-> mtjsondictionary (0.0.4)
A nsdictionary category for when you ' re working with it converting To/from JSON. DEPRECATED, use Mtjsonutils
instead.
-Homepage:https://github.com/mysterioustrousers/mtjsondictionary.git
-Source:https://github.com/mysterioustrousers/mtjsondictionary.git
-versions:0.0.4, 0.0.3, 0.0.2 [master repo]
  
  
-> mtjsonutils (0.1.0)
A nsobject category for working with JSON.
-Homepage:https://github.com/mysterioustrousers/mtjsonutils.git
-Source:https://github.com/mysterioustrousers/mtjsonutils.git
-versions:0.1.0, 0.0.1 [master repo]
  
  
-> sbjson (3.1.1)
This library implements strict JSON parsing and generation in objective-c.
-homepage:http://stig.github.com/json-framework/
-Source:https://github.com/stig/json-framework.git
-versions:3.1.1, 3.1, 3.0.4, 2.2.3 [master repo]
  
  
-> Touchjson (1.0)
Touchjson is a objective-c based parser and generator for JSON encoded data.
-Homepage:https://github.com/touchcode/touchjson
-Source:https://github.com/touchcode/touchjson.git
-versions:1.0 [master repo]

to generate a third-party library's help document

If you want Cococapods to help you build a third-party library's help documentation and integrate it into Xcode, install Appledoc with brew:

[HTML] view plaincopyBrew Install Appledoc

As for Appledoc, I had a special introduction to the "Document generation tool using Objective-c: Appledoc" In another blog earlier this year. The biggest advantage is that you can integrate the help document into Xcode so that when you tap the code, you can click the class name or the method name to display the appropriate help document.

principle

Probably studied the principle of cocoapods, which is to put all the dependent libraries into another named Pods project, and then let the main project depends on the pods project, so that the source management work from the main project moved to the Pods project. Some of the technical details found are:

The Pods project is eventually compiled into a file called LIBPODS.A, and the main project only needs to rely on this. a file.
For resource files, Cocoapods provides a bash script called pods-resources.sh, which executes every time the project is compiled and copies the various resource files from the third-party library to the target directory.

Cocoapods uses a file called Pods.xcconfig to set all dependencies and parameters at compile time.


More iOS Madness: Http://blog.csdn.net/wanglongblog

iOS crazy detailed cocoapods do iOS package dependency management

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.