Preventing Xcode from building with #error

After recently shipping an update to Flint with a beta flag enabled, I decided to find a way to prevent it in the future. I wanted Xcode to not even build the app if conflicting conditions were enabled. I came across the #error preprocessor directive which does exactly that, and can be used like this:

#if defined(APP_STORE) && defined(BETA)
#error Beta enabled for App Store build!

Xcode Error

Next time when you try to build, it will fail and you’ll get a nice error telling you what’s wrong. Of course, I should never have had those two options enabled in the first place, but mistakes will happen, and it’s nice to have an automated sanity check built-in.