IOS development ~ CocoaPods Usage Details, ioscocoapods
I. Summary
During iOS development, many third-party libraries are referenced in the project, and CocoaPods (https://github.com/CocoaPods/CocoaPods) can be used to conveniently manage these third-party libraries in a unified manner.
Ii. Installation
Since the tutorials on the Internet are basically the same, but the details are not perfect, I would like to take the opportunity to add them here:
Note: To use CocoaPods, You need to download and install CocoaPods. to download and install CocoaPods, you need the Ruby environment.
1. Ruby Environment Construction
The current installation environment is Mac mini 10.8.5. Mac OS itself comes with Ruby, but it still updates the insurance, because the first installation of Ruby fails without updating Ruby.
A. Check the current ruby version. Open the terminal and enter ruby-v (it is installed, but this version fails to be used. Therefore, the ruby version is updated)
[Objc]View plaincopyprint?
- RitekiMac-mini: PodTest lucky $ ruby-v
- Ruby 1.8.7 (patchlevel 358) [universal-darwin12.0]
- RitekiMac-mini: PodTest lucky $
B. Update ruby
Enter the following command on the terminal (point the Ruby image to taobao to avoid being attacked)
Gem sources -- remove https://rubygems.org/
Gem sources-a https://ruby.taobao.org/
Gem sources-l (used to check whether the image is successfully replaced)
[Objc]View plaincopyprint?
- RitekiMac-mini :~ Lucky $ gem sources -- remove https://rubygems.org/
- Https://rubygems.org/removed from sources
- RitekiMac-mini :~ Lucky $ gem sources-a https://ruby.taobao.org/
- Https://ruby.taobao.org/added to sources
- RitekiMac-mini :~ Lucky $ gem sources-l
- * ** Current sources ***
2. Download and install CocoaPods
Terminal input: sudo gem install cocoapods
[Html]View plaincopyprint?
- RitekiMac-mini :~ Lucky $ sudo gem install cocoapods
- CHANGELOG:
- #0.32.1
- ##### Bug Fixes
- * Fixed the Podfile 'default _ subspec 'attribute in nested subspecs.
- [Fabio Pelosin] [irrationalfab]
- \ [#2050] (https://github.com/CocoaPods/CocoaPods/issues/2050)
- Successfully installed cocoapods-0.32.1
- Installing ri documentation for cocoapods-0.32.1
- /System/Library/Frameworks/Ruby. framework/Versions/1.8/usr/lib/ruby/1.8/rdoc. rb: 280: warning: conflicting chdir during another chdir block
- /System/Library/Frameworks/Ruby. framework/Versions/1.8/usr/lib/ruby/1.8/rdoc. rb: 287: warning: conflicting chdir during another chdir block
- Done installing documentation for cocoapods after 10 seconds
- 1 gem installed
In this way, CocoaPods is downloaded and installed.
3. Use CocoaPods
A. Create a project named PodTest.
Terminal B, cd to the project directory (note: the directory that contains the PodTest folder, PodTest. xcodeproj, and PodTestTest)
[Objc]View plaincopyprint?
- Cd/Users/lucky/Desktop/PodTest
C. Create a Podfile (configuration file)
Next, enter vim Podfile on the terminal.
Enter I on the keyboard to enter the editing mode. Enter
Platform: ios, '7. 0'
Pod 'mbprogresshud ',' ~> 0.8'
Then Press Esc and enter ":" to enter the vim command mode, and then enter wq behind the colon
Note: You can enter wq only after entering: on the keyboard. Press enter and you will find one more Podfile file in the total directory of the PodTest project.
Exciting time: confirm the terminal cd to the project directory, then enter pod install, wait for a while, about 3 minutes.
View the project root directory:
Note: To open a project, click PodTest. xodeproj instead of PodTest. xcworkspace.
Open the project and check the project structure:
Running result:
Supplement:
1. The basic installation and use of CocoaPods are described in detail, but there are some supplements. What should I do when multiple third parties need to be imported at the same time?
In this case, you need to modify the Podfile, which is the file saved in the project root directory edited by vim. After modifying the Podfile file, you need to re-execute the pod install command.
For example:
Platform: ios
Pod 'jsonkit', '~> 1.4'
Pod 'afnetworking', '~> 2.0'
2. CocoaPods can find the third-party library you want
Terminal input command: pod search UI
Crazy. How can I find such a popular keyword? Many databases ~~
Then re-edit the Podfile file and follow the previous steps to import more databases to the project!