Installing RestKit v0.20.x as a Git Submodule

hashemp206 edited this page May 10, 2014 · 7 revisions

Installing RestKit v0.20.x as a Git Submodule

This document describes the installation process for getting RestKit installed into an iOS project built using Xcode 4.x. If you have trouble building or running your app after completing the guide, please refer to the Installation Troubleshooting wiki page.

Installation via CocoaPods

The recommended installation mechanism for RestKit is via CocoaPods. CocoaPods is an Objective-C library dependency manager that streamlines the process of installing, configuring, and updating third-party libraries.

Please consult the Installing RestKit v0.20.x via CocoaPods page if you wish to utilize CocoaPods to install RestKit.

You can learn more about CocoaPods at the website:

Adding the Submodule

If you do not wish to use CocoaPods then the secondary recommendation is to use a submodule. This allows you to easily track updates using standard Git commands. The first step to installation is to add the submodule to your project:

$ cd /path/to/MyApplication
# If this is a new project, initialize git...
$ git init
$ git submodule add git://
$ git submodule update --init --recursive
$ open RestKit

You can substitute an alternative branch (i.e. development) via the -b switch to the git submodule invocation. (i.e. git submodule add -b development git:// Add Submodule

Adding RestKit to Your Project

Now that you have cloned RestKit into your project, you need to let your project know about RestKit by adding it to your project Workspace. Find the RestKit.xcodeproj file inside of the cloned RestKit project directory and drag it into the Project Navigator (⌘+1). Add Project Dependency

Configuring Your Target

Now that your project is aware of RestKit, you need to configure a few settings and add some required Frameworks to your project's build configuration. Click on the top-most item in the Project Navigator to open the Project and Targets configuration pane.

Then click on the Build Settings item and input "other linker flags" into the search text box in the top right of the main editing pane. Double click on the build Setting titled Other Linker Flags. A panel will pop open prompting you to input the Linker Flags you wish to add. Input -ObjC -all_load and hit Done.

NOTE: Try removing the -all_load flag if you are receiving runtime errors related to selectors not being found, even though you followed all the steps faithfully.

Add Linker Flag

After configuring the Linker Flag, clear the text from the search box and input "header search path". Double click on the build setting titled Header Search Paths. A panel will pop open prompting you to input the Header Search Path you wish to add. Input "$(BUILT_PRODUCTS_DIR)/../../Headers". Be sure to include the surrounding quotes (-- they are important!) and hit Done. Add Header Search Path

Now click on the Build Phases tab and click the disclosure triangle next to the item titled Target Dependencies. A sheet will pop open asking you to select the target you want to add a dependency on. Click the RestKit (for iOS) OR RestKitFramework (for OS X) target and hit the Add button. Add Target Dependency Select RestKit Target

Once the Target Dependency has been configured, you now need to link the RestKit static libraries and the required Frameworks into your target. Click the disclosure triangle next to the item labeled Link Binary With Libraries and click the plus button: Add Libraries

Select the RestKit static libraries appropriate for your configuration. The appropriate libraries to select depends on the platform (iOS or OS X) you are targeting:

  • libRestKit.a - RestKit for iOS static library

Select RestKit Static Libraries

Now you need to add linkage to the required Apple provided frameworks as well. Click the plus button again and select the following Frameworks from the iOS section of the framework selection sheet:

  • CFNetwork.framework on iOS
  • CoreData.framework
  • MobileCoreServices.framework on iOS or CoreServices.framework on OS X
  • Security.framework
  • SystemConfiguration.framework

Select Required Frameworks

Add Framework Copy Phase (OS X Only)

If your application targets OS X and you have linked in the RestKit.framework product, you need to add a Copy Files build phase to your target. From the Build Phases panel of your target's configuration, press the Add Build Phase menu button from the lower right hand region of the Xcode editor and select the Add Copy Files option. A new entry will appear in the Build Phases list. Rename this entry to "Copy RestKit Framework" and set the value for Destination drop down menu to Frameworks. Then find the RestKit.framework product within the RestKit project in the Project Navigator panel on the left and drag it into the build phase file list.

Add Copy Files Phase

Add Framework to Copy Files Phase

Updating the Precompiled Header File

You now need to update your project's Precompiled Header File to include the System Configuration and Core Services header files to avoid build warnings emitted from AFNetworking. The precompiled header file is placed in the Supporting Files group in your Xcode project by default. It is generally named after your complete project/target with the extension .pch. In the example project used to build this guide named "RestKit Installation", Xcode generated a precompiled header file named "RestKit Installation.pch". Once you have found your PCH file, replace the contents of the current #ifdef __OBJC__ with the following example code:

  #ifndef __IPHONE_5_0
    #warning "This project uses features only available in iPhone SDK 5.0 and later."

  #ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <SystemConfiguration/SystemConfiguration.h>
    #import <MobileCoreServices/MobileCoreServices.h>
  #ifdef __OBJC__
    #import <Cocoa/Cocoa.h>
    #import <SystemConfiguration/SystemConfiguration.h>
    #import <CoreServices/CoreServices.h>

You have now completed installation of RestKit into your application. To verify the installation, open up your App Delegate and add an import of the RestKit header:

#import <RestKit/RestKit.h>

Build your project (⌘+B) and then switch to the Log Navigator view (⌘+7) and verify the build output. Your project should build cleanly without any issues. Congratulations! You have now successfully installed RestKit!

Add Import to App Delegate Verify Build