Configuration Handling in Xcode

Typically, Xcode starts us out with two configurations; Debug and Release. You will find them in your project’s info page. You can create more configurations like Beta, Staging etc on demand. You can edit these configurations as required (Just create a duplicate of release or debug versions and rename it appropriately).

You can then add swift compiler flags so that we can check the current configuration through code.

To do that, goto Project (not target)Build settingsSwift CompilerCustom flags → Other swift flags section and edit the different configuration flags. Add the flags using the syntax “ -D <flag_name>”.

Image for post
Image for post

NOTE: if you are not seeing Other swift flags section, you will be in the basic build settings mode. Just select ‘All’ as in the screenshot below.

Image for post
Image for post

Now, we can use these flags in code to check the current configuration like:

Now, For changing current scheme, goto your TargetEdit scheme . Then under the info tab, click and change the build configuration as required.

Suppose if you are having different constants for release and debug app, follow the above pattern of configuration management which helps in minimising the errors.

ENJOY!!

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store