Reprint please contact the author to obtain authorization, and marked the author, thank you, there is a moral conscience!
- What is CocoaPods CocoaPods is OS X and iOS under a third class library management tools, through CocoaPods tools we can add to the project called “dependent Pods library” (these libraries must be supported by the CocoaPods itself), and can easily manage the version.
- The benefits of cocoaPods 1, in the introduction of the third party library, it can automatically complete a variety of configurations for us, including the configuration of the compilation phase, connector options, and even the ARC environment -fno-objc-arc configuration.
2, CocoaPods can easily find a new third party library, the library is a “standard”, and not easily find online, so that we can find a really good library.
Two, Cocoapods installation steps
Note: when you enter a command at the terminal, take the back part of the input
1, upgrade the Ruby environmentTerminal input: $gem update --system
At this time will appear
no permission to upgrade Ruby tips
This is because you do not have permission to upgrade RubyThis should be entered: $sudo gem update --system
At this time there will be
Then enter the password, note: enter the password when there is no response, the cursor will not move, even though you are the input, the loss of direct return.
wait a minute if there is
upgrade Ruby success
Congratulations, upgrade Ruby is successful.
2, replace the Ruby image
First remove the existing Ruby imageTerminal input: $gem sources --remove https://rubygems.org/
Then add the latest image source (Taobao’s Ruby image is not updated)Terminal input: $gem source -a https://gems.ruby-china.org/
After the completion of the implementation of the input gem sources -l to view the current imageTerminal input: $gem sources -l
If the result is
* * * CURRENT SOURCES * * *
successfully added, otherwise continue to add https://gems.ruby-china.org/ -a source $gem
3, install CocoaPods
Next installTerminal input: $sudo gem install cocoapods
shows no permissions required to enterTerminal input: $sudo gem -n /usr/local/bin install cocoapods
The installation is as follows:
To do this after pod setup (PS: this process is long, be patient)Terminal input: $pod setup
Then you will see the emergence of the Setting up master repo, stuck motionless, indicating that Cocoapods in its information to download to ~/.cocoapods CocoaPods.
command+n you can create a terminal window, execute the CD ~/.cocoapods/ into the folder, then the implementation of Du * -sh to view the file size, every few minutes at a time, the final directory size is more than and 900 M (I 930M) when Setup completed
that has been completed.
Ha ha, it is not easy, and finally come to this step, and finally completed the installation, so in the end can not use it? Let’s look down!
note: all of the above steps are configured for this computer CocoaPods environment, the following is the real CocoaPods installed in your project.
4, the use of CocoaPods
1, we first look at the three party LibraryTerminal input: $pod search AFNetworking
At this time there may be
This is because the time before the pod
to generate the cache file to execute RM ~/Library/Caches/CocoaPods/search_index.json to delete the file and then enter the
pod search AFNetworking
Creating to search that will prompt search index for spec repo’master’..
will wait while the search results appear again as follows:
AFNetworking search results
The emergence of a note on the successful search, see above in this sentence:
this sentence for us to use, this is the key field to add CocoaPods three party libraries
2, create a Podfile file in the project
To create a Podfile file in your project, you must first enter the project directoryTerminal input: $CD /Users/liyang/Desktop/CocoaPodsTest
Come in and createTerminal input: $touch Podfile
Then you can see more than one Podfile file in your project directory
3, edit the name and version of the third party library you want to import
Use VIM to edit Podfile filesTerminal input: $VIM Podfile
Enter the following interface:
edit Podfile file
After coming in, followed by the keyboard on the English’i’key
below “Podsfile” 0L, 0C will become – INSERT –
and then you can edit the text, enter the following textPlatform: IOS,'7.0'target do pod "AFNetworking", "~> 3.1.0" end'MyApp'
Explain that’MyApp’is your project name: IOS, platform,’7.0′ represents the current AFNetworking support the lowest iOS version is iOS 7,’~> 3.1.0’to download the AFNetworking version is version 3.1.0 and above
After editing as follows:
at this time to quit, how to quit? Follow me, first press the upper left corner of the ESC key, then press: key, and then enter the WQ, click enter, save and exit.
At this time, you will find that the contents of the file in your project directory named Podfile are what you just typed.
4, download the library to XcodeTerminal input: $pod install
This began to download, it takes some time, the following interface shows that the installation of
This time to close all of the Xcode window, and then open the project directory will see more than a suffix named.Xcworkspace file.
After opening the project double-click on the file to open, and is no longer open the.Xcodeproj file.
into the project after the introduction of the header file is no longer #import “AFNetworking.h”, but #import < AFNetworking.h>
Finally finished, almost 1 points, and do not ask for praise, not to reward, but can help more people!
if there is what is wrong or inadequate, but also hope readers can give opinions or suggestions