Little white level CocoaPods installation and use tutorial

Article / Jiuxi (author of Jianshu)
original link: http://www.jianshu.com/p/e2f65848dddc
The copyright belongs to the author, please contact the author for authorization, and mark "author of Jianshu".

Baidu has a lot of installation tutorials for CocoaPods. When I read it for the first time, I really felt a little incomprehensible. After thinking and practicing step by step, it took 30 minutes before and after to use it smoothly. =.= So I thought about it. , I'd better write a beginner-level tutorial. It will explain every detail. Let you solve CocoaPods in 10 minutes.

Introduction to CocoaPods

When each language develops to a stage, corresponding dependency management tools will appear, such as Maven in Java language and npm in nodejs. With the increase of iOS developers, the industry also has a tool to provide dependency management for iOS programs, its name is CocoaPods.

The source code of the CocoaPods project is managed on Github. The project started on August 12, 2011 and has grown over the years to become the de facto standard tool for dependency management in iOS development. The development of iOS projects inevitably requires the use of third-party open-source libraries, and the emergence of CocoaPods allows us to save time in setting up and updating third-party open-source libraries.

The official website of CocoaPods: https://cocoapods.org/

Replace the official ruby ​​source with the source of domestic Taobao

ruby's software source rubygems.org is blocked because of the use of Amazon's cloud service, and the source of ruby ​​needs to be updated.

gem sources --remove https://rubygems.org/ //Remove ruby ​​software sources

gem sources -a http://ruby.taobao.org/ //Add Taobao source

gem sources -l //View ruby ​​software sources


 

Install

The installation method is very simple. Mac comes with ruby. You can download and install it using the ruby ​​gem command:

sudo gem install cocoapods //The user password will be filled in because of the sudo super permission

If your gem is too old, there may also be problems. You can try to upgrade the gem with the following command:

sudo gem update --system


Start downloading, due to the network, it takes a long time to wait.

If downloaded, "20 gems installed" will appear

View download progress

 


 

Cocoapods is downloading its information to the ~/.cocoapods directory. If you wait too long, try cd to that directory and use du -sh * to check the download progress.


Query download progress

pod setup

When pod setup is executed, it will output Setting up CocoaPods master repo


After installation, "Setup completed" will appear

Using Podfiles

You may ask here, why can CocoaPods download AFNetworking instead of downloading other class libraries? The answer to this question is that there is a file that controls what CocoaPods should download. This file is called "Podfile" (note that it must be the file name and no suffix). You create a Podfile, and then add the class library you need to download in it, which is to tell CocoaPods, "So-and-so and so-and-so, come to the bowl!". Only one Podfile is required per project.

Well, without further ado, let's create this magic PodFile first. Enter (cd command) the directory where your project is located in the terminal, and then in the current directory, use vim to create a Podfile, and run:

 came Podfile

Then enter the following text in the Podfile:

platform :ios, '7.0'

pod "AFNetworking", "~> 2.0"

The meaning of these two sentences is that the highest version of iOS currently supported by AFNetworking is iOS 7.0, and the version of AFNetworking to be downloaded is 2.0.

actually,

platform :ios 

under 'AFNetworking'

That's it. The latest stable version will be automatically available.

In vim environment, the save and exit command is: 

:wq

Some people have never used vim. Just type: wq ->Enter , nothing happens.

It is actually like this: ESC -> :wq -> enter You will find that the cursor has moved to the bottom.

use

Then you put the edited Podfile file in your project root directory and execute the following command:

cd "your project root directory"

pod install

Now that all your third-party libraries have been downloaded and the compilation parameters and dependencies are set, you only need to remember the following 2 points:

Use the .xcworkspace file generated by CocoaPods to open the project instead of the previous .xcodeproj file.

Every time you change the Podfile, you need to re-execute the pod update command.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327007231&siteId=291194637