Skip to content

Instantly share code, notes, and snippets.

@jaylyerly
Created April 6, 2017 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaylyerly/266710aed54900baa194f14f10153551 to your computer and use it in GitHub Desktop.
Save jaylyerly/266710aed54900baa194f14f10153551 to your computer and use it in GitHub Desktop.
This implementation of main() for a Mac application dynamically switch the AppDelegate at runtime based on the presence of the TestingAppDelegate class, which is only available during unit testing.
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
if (NSClassFromString(@"AppNameTests.TestingAppDelegate") != nil) {
id appDelegate = [[NSClassFromString(@"AppNameTests.TestingAppDelegate") alloc] init];
NSApplication * application = [NSApplication sharedApplication];
[application setDelegate:appDelegate];
[NSApp run];
} else {
return NSApplicationMain(argc,(const char **) argv);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment