Wandering iOS
Original address 1:http://iostree.sinaapp.com/?p=78 original address 2:http://blog.csdn.net/wzzvictory/article/details/18737437iOS third-party library management tool podsMany use third-party libraries are very cool, can omit a lot of code, greatly saving our development time, but, for many beginners, the use of super trouble, it is possible that each third-party library requires a different configuration steps, and is prone to error. Here I would like to share a very useful tool-pods, share before I read some information on the Internet, and according to some of my experience wrote this blog.===========================================================Catalogue1------Check 2------installation 3------upgrade 4------use ===========================================================1, check before installing pods, We first check whether the computer has installed pods tools, if it has been installed, then we can skip the 2nd and 3rd steps to the 4th step! How do I check if I have installed it? Open Computer Terminal input:
$ which pod
If one is installed, the results are displayed:
/usr/bin/pod
If it has not been installed, then nothing happens! Then we need to take the second step! 2, installation if you confirm that the computer has not been installed pods, then we directly on the terminal input:
$ sudo gem install Cocoapods
In this installation process may be slow, there seems to be no response, it is normal! Wait patiently for two or three minutes! If two or three minutes still does not respond, then directly interrupt the installation program:
Using keyboard shortcuts ctl+c
Then enter:
$ gem Sources--remove https://rubygems.org/
Then enter:
$ gem sources-a http://ruby.taobao.org/
Then verify the new Ruby image that you just set for the two commands:
$ gem sources-l
When the verification is complete, it will appear:
Current SOURCES * * *
http://ruby.taobao.org/
Finally, the pods can be installed quickly:
$ sudo gem install Cocoapods
3. Upgrade
In the 1th step, if you installed can update also can not update pods, if need to update then enter: sudo gem update cocoapods
4. Use
So after installing the pods, the next thing to do is how to manage your third-party library in the project.
The next step is to experience the magic of Cocoapods, which takes the following steps:
To demonstrate this process, I created a project called Cocoapodstest.
1. Create Podfile
Cocoapods everything starts with a file named Podfile, we need to create this file first. Personal habits using the command line, I will do this:
- $ cd/users/wangzz/desktop/cocoapodstest
- $ Touch Podfile
First go to the project root directory, create a blank podfile file, create a complete directory structure such as:
(Ps:podfile file can also not be placed in the root of the project, just a little bit of trouble, in the next article will be introduced, please pay attention. )
2. Edit Podfile
As needed, we can write the required third-party libraries in the Podfile file, for example, Sbjson, Afnetworking, reachability three libraries, my podfile content is as follows:
[OBJC]View Plaincopy
- Platform:ios
- Pod ' reachability ', ' ~> 3.0.0 '
- Pod ' Sbjson ', ' ~> 4.0.0 '
- Platform:ios, ' 7.0 '
- Pod ' afnetworking ', ' ~> 2.0 '
3. Execute the Import command
When the preparation is complete, start importing third-party libraries:
- $ cd/users/wangzz/desktop/cocoapodstest
- $ pod Install
First go to the engineering root directory, and then execute the pod Install command, cocoapods started to download the source code for us, configure dependencies, introduce the required framework and other columns of work, command execution results are printed as follows:
- Analyzing dependencies
- Downloading dependencies
- Installing Afnetworking (2. 1. 0)
- Installing Jsonkit (1. 5pre)
- Installing reachability (3. 0. 0)
- Generating Pods Project
- Integrating client Project
- [!] From "On" Use ' cocoapodstest. Xcworkspace '.
This means that the pod install command was executed successfully. Take a look at the changes in the engineering root directory, such as:
As you can see, there are three more things under the project's root directory: Cocoapodstest.xcworkspace, podfile.lock files, and pods directories.
(PS: Limited space, Podfile.lock file will be placed in the next article of the series, please pay attention to. )
Take a look at the last line of content that was printed just after the pod install command was executed:
- [!] From "On" Use ' cocoapodstest. Xcworkspace '.
Tip us from now on, we need to use the Cocoapodstest.xcworkspace file to develop.
For changes in engineering, there are several points to note:
- Third-party libraries are compiled into static libraries for our real project use
Cocoapods will create a project called Pods with all third-party libraries as Target, and the project will be placed in the newly generated pods directory. The entire third-party library project will generate a static library called LIBPODS.A to provide our own Cocoapodstest engineering use.
- Our project and the third party Libraries project will be managed by a newly generated workspace
To facilitate our intuitive management of engineering and third-party libraries, cocoapodstest engineering and Pods engineering will be organized and managed in the form of workspace, the Cocoapodstest.xcworkspace file we have just seen.
The original project settings have been changed, this time we directly open the original project files to compile will be error, can only use the newly generated workspace for project management.
Open Cocoapodstest.xcworkspace, the interface is as follows:
The catalog structure of the project is still very obvious.
Reference the header file of the third-party library that you just added in the project, perform the compilation operation, decisive success!
iOS third-party library management tools