Skip to content

Detailed Library Integration instructions

AliSoftware edited this page May 3, 2014 · 10 revisions

Detailed integration instructions

Warning about AppStore releases

OHHTTPStubs is designed to be used in test/debug code only: Don't forget not to link with it in production code when you compile your final application for the AppStore or your stubs will still be active in your official release, which is probably not what you want.

So you will probably only link it with your Unit Tests target, or inside some #if DEBUG/#endif portions of your code._

Using CocoaPods

The recommended way to integrate OHHTTPStubs in your project is using CocoaPods. Simply add the pod OHHTTPStubs line in your Podfile and you are good to go.

Be careful anyway to include it only in your test targets, or only use its symbols in #if DEBUG portions, so that its code (and the private API it uses) is not included in your release for the AppStore, as explained above.

Integrating the library manually

If you prefer to integrate OHHTTPStubs manually, simply add the xcodeproj in your workspace and link the library produced by this xcodeproj with your application.

To do this, you should follow the following detailed instructions:

  1. Add the OHHTTPStubs.xcodeproj project to your application workspace, next to your application project
  2. Build the library once for the "iOS Device" destination (if you skipt this, you will likely have the Xcode4 bug described below)
  3. Link libOHHTTPStubs.a with your application project:
  • Select your application project in the Project Navigator, then select your target in which you want to use OHHTTPStubs (for example your Tests target if you will only use OHHTTPStubs in your Unit Tests)
  • Go to the "Build Phase" tab and open the "Link Binary With Libraries" phase
  • Use the "+" button to add the libOHHTTPStubs.a library to the libraries linked with your project
  1. Select the libOHHTTPStubs.a file reference that has been added to your application projet, and change the "Location" dropdown (in the "File Inspector" pane) to "Relative to Build Products" if it is not already.
  2. When you need to use OHHTTPStubs classes, import the headers using #import <OHHTTPStubs/OHHTTPStubs.h>

Fixing Xcode4 "Relative to Build Products" bug

Due to a bug in Xcode4, when linking with a library built by another project in the workspace, Xcode do add the library file reference to the project, but does not reference its path correctly (namely "Relative to Build Products") but relative to some absolute path.

This bug leads to problems for Xcode to detect implicit dependencies. Hopefully, it can be easily fixed.

First, if you followed steps above, especially steps 2 and 4, you should have work around this bug and won't have the problem at all. If not, here is a definitive fix for this problem:

  • In the Finder, right-clic on your application's xcodeproj project file and select "Show Package Contents"

  • Double-clic on the "project.pbxproj" file inside that project bundle to open it (or open it with your favorite text editor)

  • In this text file, locate the occurrences of "libOHHTTPStubs.a" in the "PBXFileReference" section. You should find a line like this (probably with another id instead of the 097935A1161B654E006DB5D5 below):

097935A1161B654E006DB5D5 /* libOHHTTPStubs.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "../../....../libOHHTTPStubs.a"; sourceTree = BUILT_PRODUCTS_DIR; };


* Fix the "path = " part of this line to only be `path = "libOHHTTPStubs.a";`
* Make sure too that the end is `sourceTree = BUILT_PRODUCTS_DIR;` and not other value for `sourceTree`
* Save and close the `project.pbxproj` file

_Note: You don't even have to close your project/workspace in Xcode while you do those steps to fix the `project.pbxproj` file!_