Take the 2-minute tour ×

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.

share|improve this question
add comment

1 Answer

up vote 27 down vote accepted

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

// Simulator code

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)

share|improve this answer
As of 4.2 when the simulator is in iPad-mode it appears to always return iPhone Simulator. –  zekel Jun 2 '11 at 17:42
add comment

Your Answer


