First, IntroductionCocoapods official websitehttps://guides.cocoapods.org What is Cocoapods?Cocoapods is a third-party open source Class Library management tool under OS X and iOS, and with the Cocoapods tool we can add a dependent library called "Pods" to the project (which must be supported by the Cocoapods itself) and can easily manage its version.
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.
Cocoapods appearance of the backgroundDeveloping IOS projects inevitably uses third-party open source libraries, and before using cocoapods, development projects need to use third-party open source libraries, we need to
1. Copy the source code to the project.
2. Add some dependent frameworks and dynamic libraries.
3, set the 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.
benefits of using Cocoapods1, in the introduction of third-party libraries, it can automatically complete a variety of configurations for us, including the configuration of the compilation phase, connector options, and even the arc environment of the-FNO-OBJC-ARC configuration.
2, the use of cocoapods can easily find a new third-party library, these libraries are "standard", rather than casually found on the internet, so that we can find a really useful class library.
the principle of cocoapodsThe 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.
Second, installation1. Install Ruby Environmenthere's how to install Ruby:1), install through Ruby source code1>, download Ruby source from Ruby official website, https://www.ruby-lang.org/en/downloads/, unzip2>, CD to unzip directory, execute$./configure
3>, execution
$ make
4>, execution
$ make Install 5>, execution
$ buby-v2) , upgrading Ruby through RVM (recommended)1>, installing RVM Rvm:ruby version manager, Ruby release manager, including Ruby version management and GEM Library Management (Gemset)
$ curl-l Get.rvm.io | Bash-s Stable
2>, load the file, test whether the installation is normal (follow the prompts) $ source ~/.BASHRC
$ source ~/.bash_profile
$ source ~/.profile
$ rvm-v
3>, get RVM list
$ RVM list known
4>, installation ruby2.4
$ RVM Install 2.4
You may encounter the following error during installation: Error running ' requirements_osx_port_libs_install curl-ca-bundle automake libtool libyaml Libffi Libksba ', showing last lines Of/users/acewill/.rvm/log/1468253599_ruby-2.3.0/package_install_curl-ca-bundle_ Automake_libtool_libyaml_libffi_libksba.log
The reason is that you need to install homebrew, referring to the problem on the stack overflow installing RVM: "Requirements installation failed with status:1." Install homebrew by following the Make:
$ RUBY-E "$ (curl-fssl hhtps://raw.githubusercontent.com/homebrew/install/master/install)"
After installing homebrew, reinstall Ruby
$ RVM Install 2.4
2. Set up Ruby's software source$ Gem Sources-l # (View the source of the current ruby)
$ gem Sources--removehttps://rubygems.org/# (removes the current ruby source)
$ Gem sources-ahttps://gems.ruby-china.org/# (Set the current Ruby source, Taobao image is no longer available, can be used https://gems.ruby-china.org)
$ gem Sources-l # (see the source of the current Ruby again)
If the terminal output:
Current SOURCES * * *
https://gems.ruby-china.org/indicates successful switchover
3. Set gem to the latest version if the gem is too old, you can try upgrading the gem with the following command:
$ gem Update--system
After successful upgrade, you will be prompted: Latest version currently installed. Aborting.
If the error:while executing gem appears ... (OPENSSL::SSL::SSLERROR) hostname "upyun.gems.ruby-china.org" does not match the server certificate reason is that the previously used Ruby image source is Taobao , need to switch to https://gems.ruby-china.org/, in terminal input
$ gem Sources-remove https://ruby.taobao.org/
$ gem sources-a https://gems.ruby-china.org/
4, Installation Cocoapods
The first method: Git Clone method installation Cocoapods$ CD ~/.cocoapods/repos
Cloning a specs Library
$ git clone https://github.com/CocoaPods/Specs
When finished, execute open. Open current directory Repos
$ open.
Then rename the specs directory to master.
If Gitclone is still slow, directly on the https://github.com/CocoaPods/Specs click Download, according to the above directory structure diagram, lil bit is good
Then execute the POD search third-party framework
$ pod Search afnetworking
See the following information to illustrate the success.
Press Wq to exit
If it appears [!] Unable to find a pod with name, author, summary, or description matching ' afnetworking ' perform the following operation to delete the index
$ RM ~/library/caches/cocoapods/search_index.json
And then re-execute
$ pod Search afnetworking
Second method: Install with the Gem command (not recommended, slower, recommended first method)$ sudo gem install cocoa pods
Note: After upgrading OS X EL Capitan, the Apple system should read:
$ sudo gem install-n/usr/local/bin cocoapods
$ pod Setup
Will output setting up CocoaPods master repo, 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. You can also use the following section of the image index in cocoapods to improve download speed.
third, the use 1, the new project, and CD to the project directory 2. New Podfile file $ vim Podfile 3, press I (English input status) to enter the editing state 4, enter the appropriate third-party and version, such as
5, edit, first press ESC, and then enter: Wq (English input status) save Exit
6. Import third-party libraries $ pod Install
After success, a file with the same name as the project and a Pods folder will be generated under the directory, but with the suffix. Xcworkspace.
7. You need to open the project file with the suffix. Xcworkspace, and the encoding will be done in this file.The project directory structure is as follows 8. Use of third-party libraries
Perform the following actions
At this point, in the project with Cocoapods import third-party library has been completed successfully, then you can continue to happily to the code. If you later need to add additional third-party libraries or update the current third-party libraries, repeat step 2-6.
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.