Skip to content

Instantly share code, notes, and snippets.

@sheminusminus
Created March 10, 2018 04:55
Show Gist options
  • Save sheminusminus/0d630eba44cd287b483ae0060ecdac9d to your computer and use it in GitHub Desktop.
Save sheminusminus/0d630eba44cd287b483ae0060ecdac9d to your computer and use it in GitHub Desktop.

create schemes for each env

Product > Scheme > Edit Scheme > click Duplicate Scheme

This basically creates a new env configuration, so I named the new one Vibee Staging. Then I duplicated it again, and named the third one Vibee Production.

add env variables to each scheme

To add environment variables, choose edit scheme again, and:

  1. In the edit dialpg that launches, click Run on the left pane, then the Info tab. If you're in a development configuration, the Build COnfiguration should be set to Debug. If in a staging or production scheme, this should be set to Release.

  2. Stay in the Run section, but go to the Arguments tab. In the environment variables section, click the plus to add some.

(Make sure to add any variables you create to all the other schemes that you've created as well)

access env from the code

You can access them via ProcessInfo API:

let PROCESS_ENV = ProcessInfo.processInfo.environment
let BASEURL = PROCESS_ENV["API_BASE_URL"]!

switch between env configurations

Whatever scheme is selected when you run or archive the project, those env variables will be available at runtime.

You can switch between the environments like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment