Reputation: 6337
Is there any way I can conditionally compile in my app based upon whether I'm building for the simulator or the device? (My app hooks to an external server: if I'm running on the device, I want to connect to localhost; if I'm running on the device, I want to go to my production server.)
I'm looking for some #ifdef variable I can detect, or even something at runtime...doesn't matter.
Thanks.
Upvotes: 13
Views: 4040
Reputation: 2962
I created a macro in which you can specify which actions you want to perform inside parentheses and these actions will only be performed if the device is being simulated.
#define SIM(x) if ([[[UIDevice currentDevice].model lowercaseString] rangeOfString:@"simulator"].location != NSNotFound){x;}
This is used like this:
SIM(NSLog(@"This will only be logged if the device is simulated"));
Upvotes: 1