IOS development ~ CocoaPods Usage Details, ioscocoapods

Source: Internet
Author: User
Tags install cocoapods

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?
  1. RitekiMac-mini: PodTest lucky $ ruby-v
  2. Ruby 1.8.7 (patchlevel 358) [universal-darwin12.0]
  3. 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?
  1. RitekiMac-mini :~ Lucky $ gem sources -- remove https://rubygems.org/
  2. Https://rubygems.org/removed from sources
  3. RitekiMac-mini :~ Lucky $ gem sources-a https://ruby.taobao.org/
  4. Https://ruby.taobao.org/added to sources
  5. RitekiMac-mini :~ Lucky $ gem sources-l
  6. * ** Current sources ***

 

 

2. Download and install CocoaPods

Terminal input: sudo gem install cocoapods

 

[Html]View plaincopyprint?
  1. RitekiMac-mini :~ Lucky $ sudo gem install cocoapods
  2. CHANGELOG:
  3. #0.32.1
  4. ##### Bug Fixes
  5. * Fixed the Podfile 'default _ subspec 'attribute in nested subspecs.
  6. [Fabio Pelosin] [irrationalfab]
  7. \ [#2050] (https://github.com/CocoaPods/CocoaPods/issues/2050)
  8. Successfully installed cocoapods-0.32.1
  9. Installing ri documentation for cocoapods-0.32.1
  10. /System/Library/Frameworks/Ruby. framework/Versions/1.8/usr/lib/ruby/1.8/rdoc. rb: 280: warning: conflicting chdir during another chdir block
  11. /System/Library/Frameworks/Ruby. framework/Versions/1.8/usr/lib/ruby/1.8/rdoc. rb: 287: warning: conflicting chdir during another chdir block
  12. Done installing documentation for cocoapods after 10 seconds
  13. 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?
  1. 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!

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.