In every iOS or OS X app there are many configurations like API base url, keychain service name, keys for various 3rd party services. Some of them are different for Debug and Production, which leads to numerous
#ifdef’s across all the project and so on.
Here I will show quick and convenient way to manage project compile-time dependencies in
Add new configs in Xcode:
File > New > File… > Other > Configuration Settings File.
Most configuration values will be stored in
And only ones that different to build configuration will be overridden, like in
Translation in preprocessor macro will happen in
You can see, for each value we adding
Bridging header is needed to access preprocessor definitions from Swift code. It can be empty if you don’t use any obj-c sources.
Project > Info > Configurations and select there corresponding configs. I have CocoaPods project, so I am adding this configurations on project-level, not target-level.
You can use macros everywhere in your code, you don’t have to import anything:
Also, I like to move some values from Info.plist (like bundle version and display name), so all my configs stored in one place:
Thanks to Paul Taykalo for sharing this way of managing configurations.