Skip to content

Creating a project that uses CocoaPods

siuying edited this page Mar 14, 2012 · 32 revisions

Preliminary version of the basic usage howto.

  1. Create a Podfile with dependencies.
  2. Run pod install App.xcodeproj, where App.xcodeproj is your Xcode project.
  3. Open App.xcworkspace and build away.

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

“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 form 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).
    • 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
  5. If you tried to submit app to App Store, and found that "Product" > "Archive" produce 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.

TODO:

  • Add images for each step and expand on steps. Feel free to improve.