Note, untested on Xcode 5.
I used @jon-reid’s answer, but found that Xcode adds environment-variables to the xcuserstated
part of XcodeProjects, and these are user specific and not typically committed to the repository. Thus I swizzle my AppDelegate
to override its loading:
@implementation MyAppDelegate (Testing)
+ (void)initialize {
SEL new = @selector(application:didFinishLaunchingWithOptions:);
SEL orig = @selector(swizzled_application:didFinishLaunchingWithOptions:);
Class c = [self class];
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, newMethod);
}
}
- (BOOL)swizzled_application:(id)app didFinishLaunchingWithOptions:(id)opts {
return YES;
}
@end
Note, that the following is simpler and still works, though I'm not sure it is reliable:
@implementation MyAppDelegate (Testing)
- (BOOL)application:(id)app didFinishLaunchingWithOptions:(id)opts {
return YES;
}
@end
This works because categories of methods in dynamically loaded components (like the testing bundle) take precedence. Swizzling feels safer though.