Using CocoaPods

print
https://guides.cocoapods.org/using/using-cocoapods

 

Adding Pods to an Xcode project

Before you begin

  1. Check the Specs repository or cocoapods.org to make sure the libraries you would like to use are available.
  2. Install CocoaPods on your computer.

<Installation

  • Create a Podfile, and add your dependencies:
target 'MyApp' do
  pod 'AFNetworking', '~> 3.0'
  pod 'FBSDKCoreKit', '~> 4.9'
end
  • Run $ pod install in your project directory.
  • Open App.xcworkspace and build.

<Creating a new Xcode project with CocoaPods

To create a new project with CocoaPods, follow these simple steps:

  • Create a new project in Xcode as you would normally.
  • Open a terminal window, and $ cd into your project directory.
  • Create a Podfile. This can be done by running $ pod init.
  • Open your Podfile. The first line should specify the platform and version supported.
platform :ios, '9.0'
  • In order to use CocoaPods you need to define the Xcode target to link them to. So for example if you are writing an iOS app, it would be the name of your app. Create a target section by writing target '$TARGET_NAME' do and an end a few lines after.
  • Add a CocoaPod by specifying pod '$PODNAME' on a single line inside your target block.
target 'MyApp' do
  pod 'ObjectiveSugar'
end
  • Save your Podfile.
  • Run $ pod install
  • Open the MyApp.xcworkspace that was created. This should be the file you use everyday to create your app.

<Integration with an existing workspace

Integrating CocoaPods with an existing workspace requires one extra line in your Podfile. Simply specify the .xcworkspace filename in outside your target blocks like so:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.