-
Notifications
You must be signed in to change notification settings - Fork 602
Detailed Library Integration instructions
The recommended way to integrate OHHTTPStubs
in your project is using CocoaPods.
Simply add the pod OHHTTPStubs
line in your Podfile
, then run pod install
and you are good to go.
Reminder: You probably don't want to keep your stubs when releasing for the AppStore, so be careful to only include it in your test targets, or only use its symbols in
#if DEBUG
portions to avoid your AppStore version to still be stubbed 😉 See below for details.
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:
- Add the
OHHTTPStubs.xcodeproj
project to your application workspace, next to your application project - Build the library once for the "iOS Device" destination (if you skipt this, you will likely have the Xcode4 bug described below)
- 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 useOHHTTPStubs
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
- 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. - When you need to use
OHHTTPStubs
classes, import the headers using#import <OHHTTPStubs/OHHTTPStubs.h>
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 the097935A1161B654E006DB5D5
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!_
#### "unrecognised selector sent to instance" error
If you get an "unrecognised selector sent to instance" runtime error when calling one of the method declared in `OHHTTPStubs` categories, make sure that the project you want to link with `OHHTTPStubs` has the `-ObjC` flag in its "Other Linker Flags" (`OTHER_LDFLAGS`) build setting (this is normally the default in projects created in latest versions of Xcode). [See the Apple doc for more details](https://developer.apple.com/library/mac/qa/qa1490/_index.html).
## Don't forget to remove your stubs before releasing to the AppStore
`OHHTTPStubs` does not use any private API and won't gets your app rejected, but you probably don't want to ship your app to the AppStore with stubs still enabled :wink: So don't forget not to link with it in production code when you compile your final application for the AppStore.
* If you only need `OHHTTPStubs` for your Unit Tests, you can only link it with your Unit Tests target (e.g. `target :UnitTests do … end` in your Podfile)
* If you need `OHHTTPStubs` in your App Target too, you may use the new ability of CocoaPods to only activate pods for certain configurations, e.g. `pod 'OHHTTPStubs', :configuration => ['Debug']`