Using scheme environment variables
In the scheme editing window, select the Arguments tab.
The Arguments tab shows two empty lists, Arguments Passed On Launch and Environment Variables. The former we will leave for a later chapter; for now, we will concentrate on the environment variables.
The environment variables listed here are basically a dictionary of key-value pairs that are available to the app's code via the ProcessInfo.processInfo.environment dictionary, which we'll add to the app shortly:
- Click the + button to add an environment variable.
- Name the new environment variable Currency Symbol.
- Set its Value to £ or some currency symbol of your choice (New Zealand gave up its £s for $s many years ago). You must include the double quotes.
- Close the window.
If you run the app again, you'll see that the currency has changed:
This change is baked into the code in by the compiler. By testing the value of any environment variable key, we can make appropriate adjustments in the content of our code. There are various ways we could have done this, but adjusting a scheme's environment variables has got to be the simplest.
You might like to take the time now to browse through the scheme editor window's other tabs, Options, Diagnostics, and Info (the last of which we are about to use).
Any changes you want to make within the code can be covered using environment variables. The test is trivial to write and takes place at compile time. But what if we want to make changes to, say, the app's Build Settings, or even its Info.plist file? Can we do that too?
We can indeed, but not by using the scheme's environment variables. We now need to enlist the help of another one of Xcode's palette of development-sweetening goodies: build configurations.