Introduction to the

CocoaPods is a third-party open source library management tool for OS X and iOS that allows you to add dependent libraries called “Pods” to your projects. These libraries must be supported by CocoaPods. And you can easily manage its version.

advantages

1. It can automatically complete all kinds of configurations for us when introducing third-party libraries, including configuration compilation phase, connector options, and even -fno-objC-Arc configurations in ARC environments.

Using CocoaPods makes it easy to find new third-party libraries that are “standard,” rather than just found online, so that you can find useful ones.

The principle of

The idea behind CocoaPods is to put all the dependent libraries into a separate project called Pods, and then make the main project depend on the Pods project, so that the source management work is moved from the main project to the Pods project. The Pods project will eventually compile into a file called libPods.a, which the main project only relies on.

The installation

Install Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

If an error Failed to connect to port 443 raw.githubusercontent.com: Connection refused to install is not the first execution

sudo gem install redis
Copy the code

Then reinstall Homebrew and if that still doesn’t work, switch to a domestic source

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Copy the code

Install RVM

curl -L [get.rvm.io](http://get.rvm.io/) | bash -s stable
Copy the code

Load the file and test whether the installation is normal (follow the instructions)

source ~/.bashrc

source ~/.bash_profile

source ~/.profile

rvm -v
Copy the code

Get the RVM list

rvm list known
Copy the code



Install ruby3.0

RVM install 3.0Copy the code

Set up the ruby software source

Gem sources --remove https://rubygems.org/ # Remove the current ruby source gem sources -a https://gems.ruby-china.com/ # set the current ruby source, taobao mirror is no longer available, you can use https://gems.ruby-china.com gem sources -l # to check the current Ruby sourceCopy the code

*** CURRENT SOURCES *** gems.ruby-china.com/

Set the gem to the latest version

gem update --system
Copy the code

ERROR: While Executing gem… (OpenSSL::SSL::SSLError) hostname “upyun.gems.ruby-china.org” does not match the server certificate

The reason is that the ruby image source used before is taobao, so you need to switch to gems.ruby-china.com and type \

Gem sources - remove https://ruby.taobao.org/ gem sources -a https://gems.ruby-china.com/Copy the code

Install CocoaPods

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

pod setup
Copy the code

Setting up the CocoaPods master repo will be printed, but it will wait a long time. If you are waiting too long, try CD to the ~/. Cocoapods directory and use du -sh * to check the progress. Then execute pod Search third-party frameworks

pod search Moya
Copy the code

If the [!] CDN: Trunk Repo Update failed

pod repo remove trunk
Copy the code

If the [!] Unable to find a pod with name, author, summary, or description matching Moya Perform the following operations to delete the index

rm ~/Library/Caches/CocoaPods/search_index.json
Copy the code

And then re-execute it

pod search Moya
Copy the code

If you see the following information, the installation is successful

use

Create a new project and CD it to the project directory

cd ~/Desktop/test
Copy the code

Create a new Podfile

pod init
Copy the code

Open the Podfile file and add the relevant third library

Importing third-party Libraries

pod install
Copy the code

If “pod install” or “pod update” fails to match dependencies, add a parameter to the CocoaPods spec repository. If “pod install” or “pod update” fails to match dependencies, add a parameter to the CocoaPods spec repository. The command to add parameters is as follows:

pod install --verbose --no-repo-update

pod update --verbose --no-repo-update
Copy the code

A. Xcworkspace file and a Pods folder will be generated in the same directory. You need to open the. Xcworkspace project file in this file for future coding operations