Latest Mac OS X 10.12.1 installation cocoapods and usage details

Source: Internet
Author: User
Tags install cocoapods amazon cloud services

Cocoapods Official website: https://cocoapods.org

First, what is Cocoapods

As each language develops into one phase, the corresponding dependency management tools, such as the Java language Maven,nodejs NPM, are present. As iOS developers have grown, the industry has also come up with a dependency management tool for iOS programs, named CocoaPods.

The source code for the Cocoapods project is managed on Github. The project began on August 12, 2011 and, after years of development, has now become the de facto dependency management standard tool for IOS development. 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.

Second, why to use Cocoapods

Before using Cocoapods, the development project needs to use the third party open Source Library, we need

1. Copy the source code to the project

2. Add some dependent frameworks and dynamic libraries

3. Set parameters such as-objc,-fno-objc-arc

4. Manage their updates

After using Cocoapods, we just need to put the open Source library into a file called Podfile, and then execute pod install, Cocoapods will automatically download these third-party open Source Library source code, and set the system dependencies and compilation parameters for our project to be responsive.

Three, the principle of cocoapods

The cocoapods principle is that all dependent libraries are placed in another project called pods, and then the master project is dependent on the pods project, so that the source management work is moved from the main project to the Pods project. The PODS project is eventually compiled into a file called LIBPODS.A, and the main project only needs to rely on this. a file.

Iv. installation of Cocoapods

The cocoapods can be easily installed via the rubygems of the Mac itself.

Open the terminal (the Mac computer comes with the terminal), and then follow the instructions below:

1. Set up Ruby's software source

This is because Ruby's software source rubygems.org because of the use of Amazon cloud services, was blocked by my celestial, need to update the source of Ruby, the process is as follows:

Gem Sources-l # (View source for current Ruby)

Gem Sources--remove https://rubygems.org/# (removes the current ruby source)

Gem sources-a https://ruby.taobao.org/# (set current Ruby source for my celestial)

Gem Sources-l # (see the current Ruby source again)

If the terminal output:

Current SOURCES * * *

https://ruby.taobao.org/

It proves that Ruby's software source has been set OK.

2. Set the gem to the latest version

If the gem is too old, you can try upgrading the gem with the following command:

Enter the following command in Terminal:

sudo gem update--system

After successful upgrade, you will be prompted: Latest version currently installed. Aborting.

3. Execute the Install cocoapods command

Note: OS X 10.11 Upgrade, although officially claimed to be a minor upgrade, but for developers, Cocoapods need to reinstall, but follow the previous installation method, enter the following command in Terminal:

sudo gem install Cocoapods

If the following error is reported:

Error:while Executing gem ... (errno::eperm)

Operation not permitted-/usr/bin/xcodeproj

Solution 1:

Execute the following command and restart

sudo nvram boot-args= "rootless=0"

sudo reboot

After rebooting, perform this command to check

sudo gem install cocoapods-v

If there are still errors, use a second scenario

Solution 2:

sudo gem install-n/usr/local/bin cocoapods

Pod Setup

It is also important to note that POD Setup will output setting up CocoaPods master repo when it executes, but will wait a long time. This step is actually Cocoapods in the download of its information into the ~/.cocoapods directory, if you wait too long, you can try to CD to that directory, with Du-sh * To view the download progress.

After the installation is successful, you will see: Setup completed

V. Use of Cocoapods

Create a new file named Podfile in one way and put it in the root of your project (you can't write another name, or you can create your own in the project root directory)

The Podfile file contents should be formatted as follows:

Platform:ios, ' 8.0 ' # (note your development platform as well as version, ' 8.0 ' ignore not write is the latest version)

Pod ' afnetworking ', ' ~> 2.5.3 ' # (' ~> 2.5.3 ' for version number, ignore not write as latest version)

Pod ' sdwebimage ', ' ~> 3.7.2 '

Then execute in the root directory (the project root) where the terminal enters the project:

Pod Install

In this way, afnetworking and sdwebimage have been downloaded and set up the compilation parameters and dependencies, in the future when using the following two points to remember:

1. From then on, you will need to use the. xcworkspace file generated by Cocoapods to open the project instead of using the previous. xcodeproj file

2. Each time you change the Podfile file, you need to re-execute the pod update 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:

You can enter in the terminal:

Pod Search afnetworking

After you enter, you can see some library classes related to the keywords you searched for,

About Podfile.lock

After you perform the pod install, in addition to the Podfile, CocoaPods will also generate a file named Podfile.lock, Podfile.lock should be added to the version control, should not add this file to. gitignore. Because Podfile.lock locks the version of the current dependent library, if the pod install does not change the version more than once, the pod update will change podfile.lock. When many people collaborate, you can prevent third-party libraries from being upgraded with inconsistent third-party library versions

Attached: How to use Cocoapods's mirrored index:

All project Podspec files are hosted in Https://github.com/CocoaPods/Specs,

The first time you execute pod setup, Cocoapods will update these podspec index files to the local ~/.cocoapods directory.

This index file is relatively large, so the first update is very slow.

Friendly people in the domestic server set up the image of the Cocoapods Index library,

So the index is much faster than the new operation. Here's how to do it:

Pod Repo Remove Master

Pod Repo Add Master Https://gitcafe.com/akuandev/Specs.git

Pod Repo update

This is the use of gitcafe on the image, the above code in the Https://gitcafe.com/akuandev/Specs.git

Replace with Http://git.oschina.net/akuandev/Specs.git to use the mirror on the Oschina.

Latest Mac OS X 10.12.1 installation cocoapods and usage details

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.