What is Cocoapods?
When you develop an iOS app, you'll often use many third-party open source libraries, such as jsonkit,afnetworking and more. Maybe a class library to use other class libraries, so to use it, you have to have to download another class library, and other class libraries to use other class libraries, "The descendants of Endless also", this may be a more special case. It is cumbersome to manually download the required class libraries. Another common scenario is that the class libraries you use in your project are updated, and you have to re-download the new version and rejoin the project, which is a hassle. If there are any tools to solve these annoying problems, it will be "good." So, you need to CocoaPods.
Cocoapods should be the most popular class library management tool used by iOS, the two annoying problems, through cocoapods, only need a single line of command to completely solve, of course, if you have to set it up correctly. Importantly, most of the well-known open source class libraries support cocoapods. So, as an iOS programmer, mastering the use of cocoapods is essential to our basic skills. After we have cocoapods this tool, we just need to put the third-party open Source Library in a file named Podfile, and then execute the command at the command line $ 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.
Preparation before installing the Cocoapods
(1)# First install the [Xcode] (http://developer.apple.com/xcode/) development tool, which will help you install the development packages required by the Unix environment
" $ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install) "
(2) Installation RVM
$ curl-l https://Raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash-s Stable
during the period may ask you sudo administrator password, as well as automatically through Homebrew
install the dependent packages and wait a while to install the RVM successfully.
Then, load into the RVM environment (new open termal will not do so, will automatically reload)
$ source ~/.RVM/SCRIPTS/RVM
Modify RVM to download the source of Ruby to the image of Ruby China:
Echo " Ruby_url=https://cache.ruby-china.org/pub/ruby " > ~/.rvm/user/db
Check to see if the installation is correct
$ RVM-1.27. 0 (latest) by Wayne E. Seguin <[email Protected]>, Michal Papis <[email protected]> [https://rvm.io/]
(3) Installing the Ruby environment with RVM
Install 2.3. 0
Wait a very long time to download, compile the process, after completion, Ruby, Ruby Gems is installed.
(4) Set Ruby version
After the RVM is installed, you need to execute the following command to set the specified version of Ruby to the system default version
2.3. 0 --default
Also, you can use a different version number if you have a RVM install installed that version
This time you can test whether it is correct
$ ruby-2.3. 0 -v2.5. 1
Query the ruby that is already installed
$ RVM List
Uninstalling an installed version
2.0. 0
(5) Installation CocoaPods
因为Ruby的默认源使用的是cocoapods.org,国内访问这个网址有时候会有问题,网上的一种解决方案是将其替换成其他站点的,替换方式如下:
To remove the original image:
$gem source-r https://rubygems.org/
Install additional site mirroring
$https://gems.ruby-china.org/
To verify that the substitution was successful, you can do this:
$ gem sources-l
Normal output results:
Current SOURCES * * *
https://gems.ruby-china.org/
Installing Cocoapods
The ruby environment is already installed locally, so downloading and installing cocoapods will be straightforward, requiring only one line of command. Enter the following command to install CocoaPods
sudo Install Cocoapods
*-*-*-* Here CocoaPods the installation is complete *-*-*-*
Use of Cocoapods
To determine if afnetworking supports Cocoapods, you can verify it with the Cocoapods search function. In the terminal, enter:
$ pod Search afnetworking
Error occurred:
[!] /usr/bin/git Clone Https://github.com/CocoaPods/Specs.git Master
Cloning into ' master ' ...
Fatal:unable to access ' https://github.com/CocoaPods/Specs.git/': Failed-connect to github.com Port 443:operation Tim Ed out
Workaround:
sudo xcode-Select -switch/applications/xcode.app/contents/developer
Re-enter
$ pod Search afnetworking
Or is it stuck in
Setting up CocoaPods master Repo
Here for a long time, do not know what reason, waiting for a long time finally can be carried out smoothly.
Talk less, talk about how to use, toAFNetworking为例子:
(1)在工程的目录
(也就是跟***.xcodeproj文件在同一个文件夹)
下创建 Podfile (注意,一定得是这个文件名,而且没有后缀)空白文件 。你创建一个Podfile文件,然后在里面添加你需要下载的类库,也就是告诉CocoaPods,“某某和某某和某某某,快到碗里来!”。每个项目只需要一个Podfile文件。
(2)打开podfile文件,输入需要的第三方(按照下面格式输入)
' 9.0 ' Use_frameworks! #use_frameworks! ' project name ' do' afnetworking '~> 3.1'end
Save exit
(3) Terminal input
Install
(4) Open Project
. xcworkspace file
Add third party afnetworking success in this
Reference documents
(1)http://code4app.com/article/cocoapods-install-usage
(2)http://blog.csdn.net/qq_31810357/article/details/50031979
(3)http://ruby-china.org/wiki/install_ruby_guide
(4)http://blog.csdn.net/emulatestep/article/details/51644903
MacBook installation cocoapods and use