>Integrating a project

Integrating with an Xcode project

Before you begin

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

Installation

  1. Create a Podfile, and add your dependencies:
    pod 'AFNetworking', '~> 1.0'  
    pod 'ObjectiveSugar', '~> 0.5'
  1. Run $ pod install in your project directory.
  2. Open App.xcworkspace and build.

What this does

In Xcode, it:

  1. Creates or updates a workspace.
  2. Adds your project to the workspace if needed.
  3. Adds the CocoaPods static library project to the workspace if needed.
  4. Adds libPods.a to: targets => build phases => link with libraries.
  5. Adds the CocoaPods Xcode configuration file to your app’s project.
  6. Changes your app’s target configurations to be based on CocoaPods’s. (Expand the ‘To add a new build configuration…’ section of the linked page for a howto.)
  7. Adds a build phase to copy resources from any pods you installed to your app bundle. i.e. a ‘Script build phase’ after all other build phases with the following:
    • Shell: /bin/sh
    • Script: ${SRCROOT}/Pods/PodsResources.sh

Note that steps 3 onwards are skipped if the CocoaPods static library is already in your project.

This is largely based on http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4.

FAQ & Troubleshooting

“A curse a day keeps the Xcode doctor away.”

  1. If something doesn’t seem to work, first of all ensure that you are not completely overriding any options set from the Pods.xcconfig file in your project’s build settings. To add values to options from your project’s build settings, prepend the value list with $(inherited).

  2. If Xcode can’t find the headers of the dependencies:

    • Check if the pod header files are correctly symlinked in Pods/Headers and you are not overriding the HEADER_SEARCH_PATHS (see #1).
    • Make sure your project is using the Pods.xcconfig.
      To check this select your project file, then select it in the second pane again and open the Info section in the third pane. Under configurations you should select Pods.xcconfig for each configurations requiring your installed pods.
    • If Xcode still can’t find them, as a last resort you can prepend your imports, e.g. #import <Pods/SSZipArchive.h>.
  3. If you’re getting errors about unrecognized C compiler command line options, e.g. cc1obj: error: unrecognized command line option "-Wno-sign-conversion":

    • Make sure your project build settings are configured to use “Apple LLVM compiler” (clang)
    • Are you setting the CC, CPP or CXX environment variable, e.g. in your ~/.profile? This may interfere with the Xcode build process. Remove the environment variable from your ~/.profile.
  4. If Xcode complains when linking, e.g. Library not found for -lPods, it doesn’t detect the implicit dependencies:

    • Go to Product > Edit Scheme
    • Click on Build
    • Add the Pods static library, and make sure it’s at the top of the list
    • Clean and build again
    • If that doesn’t work, verify that the source for the spec you are trying to include has been pulled from github. Do this by looking in <Project Dir>/Pods/<Name of spec you are trying to include>. If it is empty (it should not be), verify that the ~/.cocoapods/master/<spec>/<spec>.podspec has the correct Github url in it.
    • If still doesn’t work, check your XCode build locations settings. Go to Preferences -> Locations -> Derived Data -> Advanced and set build location to “Relative to Workspace”.

    Xcode build location settings

  5. If you tried to submit app to App Store, and found that “Product” > “Archive” produces nothing in “Organizer”:

    • In Xcode “Build Settings”, find “Skip Install”. Set the value for “Release” to “NO” on your application target. Build again and it should work.

Different Xcode versions can have various problems. Ask for help and tell us what version you’re using.