views:

224

answers:

1

I wonder if, when building an iPhone app for the Simulator, there are special DEFINEs added that allow me to conditionally compile for this case?

If not, I'll have to add my own targets for this case, but I'd rather have an automatic way of detection.

Alternatively, is there a dynamic way to know when my code runs on the Simulator, I mean something that's documented? I've been searching the docs for a while now but had no luck yet.

+3  A: 

For compile-time check you need TARGET_IPHONE_SIMULATOR defined in TargetConditionals.h

#if TARGET_IPHONE_SIMULATOR
// Simulator code
#endif

For run-time check you can use for example -model method in UIDevice. For iPhone simulator it returns iPhone Simulator string (not sure about iPad simulator though)

Vladimir