I know the rest of the world has had this for years, and I know it’s in Flex Builder if you dig around hard enough, but seems like someone’s trying to keep it a secret. But conditional compilation in XCode is saving my life.
Big case in point: you have an iPhone simulator, which does a decent job showing most simple stuff. But it’s multitouch support is severely limited. And no accelerometer. So there are certain things you just have to run on the device. But compiling, installing on the device, and debugging from there takes several times longer than going straight to the sim.
In Gravity Pods, which I am developing for the iPhone, I have a user gesture where when the user touches on the gun, the aiming menu fades in. He can then aim and shoot. When she releases the gun, the menu fades out. Works great on the device, but sucks on the simulator because if you use your mouse to click on the gun, you can’t use it to click on the aiming menu. So, for the sim, I created an alternate gesture – pressing the gun toggles the menu. Press once, menu fades in, again it fades out.
To accomplish this, you check the environmental variable, TARGET_IPHONE_SIMULATOR. If that’s defined, you are on the simulator. If not, you are on the device. So you go like this:
[c]#if (TARGET_IPHONE_SIMULATOR)
// you are in the simulator here. implement the toggle stuff.
#else
// you are on a real live iphone. keep it real
#endif[/c]
Love it, love it, love it.
You can also do the same thing with multiple targets. For iAttractor, I had a Lite version and a full version. I set an env var in the lite target and checked that the same way to add/disable features. Works very nicely.