views:

71

answers:

1

Using the TARGET_IPHONE_SIMUATOR macro results in the same constant values being defined in am application. For example:

#ifdef TARGET_IPHONE_SIMULATOR
NSString * const Mode = @"Simulator";
#else
NSString * const Mode = @"Device";
#endif

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
   ...
   NSLog(@"Mode: %@", Mode);
   ...
}

Always results in "Mode: Simulator" being logged. I'm currently running XCode 3.2.4 if that helps. Thanks.

+3  A: 

I found a solution. It appears that TARGET_IPHONE_SIMULATOR is defined on the device (but defined to false). Thus, the fix for the above code is:

#if TARGET_IPHONE_SIMULATOR
NSString * const Mode = @"Simulator";
#else
NSString * const Mode = @"Device";
#endif

Not sure when this was changed. I'm fairly sure it was possible to use 'ifdef' in the past.

Kevin Sylvestre