iOS Development ~cocoapods Use detailed instructions

Source: Internet
Author: User
Tags vars install cocoapods

iOS Development ~cocoapods use detailed instructions

I. Summary

When iOS is developed, many third-party libraries are referenced in the project, and CocoaPods (https://github.com/CocoaPods/CocoaPods) can be used to manage these third-party libraries conveniently and uniformly.

Second, installation

As the online tutorials are basically similar, but the details are not very perfect, so the opportunity will be added here:

Note: To use Cocoapods, download and install it, and download and install cocoapods requires a ruby environment

1. Building Ruby Environment

The current installation environment is Mac mini 10.8.5. The Mac OS itself comes with Ruby, but it's still an update, because the first time I installed it failed without updating Ruby.

A view the current Ruby version: Open the terminal input ruby-v (yes, but with this version the next work fails, so update under Ruby)

[OBJC] View plaincopyprint?
    1. Ritekimac-mini:podtest lucky$ Ruby-v
    2. Ruby 1. 8. 7 (201 2-02-08 patchlevel 358) [ Universal-darwin12. 0]
    3. Ritekimac-mini:podtest lucky$

b Update Ruby

Terminal Enter the following command (point the Ruby image to Taobao, avoid being the wall, you know)

Gem Sources--remove https://rubygems.org/
Gem Sources-a http://ruby.taobao.org/
Gem sources-l (used to check for successful use of alternate mirror locations)

[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 http://ruby.taobao.org/
    4. http://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/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/rdoc.rb:287:warning:conflicting ChDir during another chdir block
  12. Done installing documentation for Cocoapods after ten seconds
  13. 1 Gem installed

This will download and install the Cocoapods

3. Using Cocoapods

A Create a new project, name Podtest

b terminal, CD-to-project directory (note: The head record containing the Podtest folder, Podtest.xcodeproj, Podtesttest)

[OBJC] View plaincopyprint?
    1. Cd/users/lucky/desktop/podtest

C build podfile (config file)

Then the last step, the terminal input vim Podfile

Keyboard input I, enter edit mode, enter

Platform:ios, ' 7.0 '
Pod ' Mbprogresshud ', ' ~> 0.8 '

Then press ESC and enter the ":" Sign into the VIM command mode and enter WQ after the colon

Note: You can enter WQ after keyboard input: Enter one more Podfile file found in the Podtest project's total directory

Exciting time to go: Determine the terminal CD to the total project directory, then enter the pod install, wait a while, about 3 minutes.

To view the project root directory:

Note: Now open the project is not click Podtest.xodeproj, but click Podtest.xcworkspace

When you open the project, you see the project structure and test it:

Operation Result:

Add:

1, the basic installation and use of cocoapods are described in detail, but there are some additions, when the need to import multiple third-party at the same time what to do?

This needs to modify the Podfile, that is, the file saved in the root directory of the project with VIM, modified 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, a lot of library ~ ~

Then re-edit the Podfile file and follow the previous steps to import more libraries into the project!

This blog stolen from Ford's blog, address: http://blog.csdn.net/lizhongfu2013/article/details/26384029

iOS Development ~cocoapods Use detailed instructions

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.