Detect in Xcode iPhone project whether I'm building for simulator or device? Detect in Xcode iPhone project whether I'm building for simulator or device? xcode xcode

Detect in Xcode iPhone project whether I'm building for simulator or device?


#if !(TARGET_IPHONE_SIMULATOR)

or, alternatively,

#if (TARGET_OS_IPHONE)

will tell you if you're running on the device. In order for it to work, you must

#include "TargetConditionals.h"

file that you can find here.


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"));