1. 程式人生 > >芒果iOS開發之Cocoapods安裝教程

芒果iOS開發之Cocoapods安裝教程

原文地址:

http://cocoapods.org

http://guides.cocoapods.org

https://github.com/CocoaPods/CocoaPods

INSTALL:

CocoaPods is built with Ruby and is installable with the default Ruby available on OS X. We recommend you do this.

Using the default Ruby install will require you to use sudo when installing gems. Further instructions are in 

the guides.

sudo gem install cocoapods

GET STARTED:

Search for pods (above). Then list the dependencies in a text file named Podfile in your Xcode project directory:

platform :ios, '7.0'
pod 'AFNetworking', '~> 2.0'
pod 'ARAnalytics', '~> 2.7'

Tip: CocoaPods provides a pod init command to create a Podfile with smart defaults. You should use it.

Now you can install the dependencies in your project:

$ pod install

Make sure to always open the Xcode workspace instead of the project file when building your project:

$ open App.xcworkspace

Now you can import your dependencies e.g.:

#import <Reachability/Reachability.h>

CREATE A POD:

Sometimes CocoaPods doesn’t yet have a pod for one of your dependencies. Fortunately, creating a pod is pretty easy:

$ pod spec create Peanut
$ edit Peanut.podspec
$ pod spec lint Peanut.podspec

You can find a lot of information on the process in the guides. When you're done you can also fork the CocoaPods specs GitHub repository and send a pull request. We really love contributions and will help ensure it's perfect!