2

My project, with one target, has three configurations:

Debug, UAT, Release

I have four shared schemes that use these configurations for build/run/test/profile/analyse/archive.

In my app I have different bundle IDs for each scheme. This was easy to change, I did so within Product Bundle Identifier for each configuration.

However, I want each scheme to connect to a different REST API. (dev.example.com/api etc)

What is the best way of setting a variable for each environment and then using it within my app?

I have looked at:

1) Swift Compiler>Custom Flags (Mine are currently $(inherited) "-D" "COCOAPODS")

2) NSProcessInfo.processInfo().environment

3) Adding a Configuration.plist file for each environment

Basically, it's not clear to me which is the best way of doing this.

Thank you for your help.

2 Answers 2

3

I usually prefer this :

I define constants in different .xcconfig files, then I use them for keys in one single plist file.

Let's say you'd have this in your debug.xcconfig :

<pre>
BASEURL = api.dev.com/api/"
</pre> 

Then, in your plist, you'd add a key baseUrl = http://${BASEURL}

Then, in code, you'd access it with NSBundle.mainBundle().infoDictionary?["baseUrl"]

This is a great article if you want to know more about xcconfig : http://www.jontolof.com/cocoa/using-xcconfig-files-for-you-xcode-project/

Sign up to request clarification or add additional context in comments.

Comments

2

Personally I use different .plist files for each scheme. I tried the custom flags approach at first, but as the app grew i needed more and more scheme-based configurations and things got messy.

Different .plist files worked wonders for my project at least.

2 Comments

Thank you for your reply. I have created three new configuration.plist files for each of the different environments following this guide here: appfoundry.be/blog/2014/07/04/Xcode-Env-Configuration I've then added the build phase. Now, these plist files are currently empty. Does each plist file need to be complete, or does it add to the info.plist? Will it work if the only thing in these plist files is the unique environment variable (the rest URL). Thanks
They either have to be complete, or you can create a new plist (not the standard info.plist) and then reference to it though a config class or something. If you do the latter you only need to duplicate the entries which are different in each plist file. Its up to you really. I duplicate everything through info.plist as I have so much changes from each environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.