0

Basically, I want to have something like

struct Config_DEVELOPMENT
{
    static let ENVIRONMENT = "PRODUCTION"
    static let BASE_URL = "https://dev.technoburgh.com"
    static let API_KEY = "dev-key"
}

struct Config_TEST
{
    static let ENVIRONMENT = "PRODUCTION"
    static let BASE_URL = "https://dev.technoburgh.com"
    static let API_KEY = "dev-key"
}

struct Config_PRODUCTION
{
    static let ENVIRONMENT = "PRODUCTION"
    static let BASE_URL = "https://dev.technoburgh.com"
    static let API_KEY = "dev-key"
}

But I'd like to be to switch the config options at run time, so QA can test out different envs at the same time, like see if an issue is reproducible in both prod & dev or just one env,etc.

I know I could use a settings bundle but I am wondering if there is a different approach to it in swift.

Scriptable
  • 18,734
  • 5
  • 56
  • 68
cbrulak
  • 15,010
  • 19
  • 60
  • 99
  • 1
    You would have to code this into your application! – Code Different Oct 28 '15 at 15:55
  • thanks for format help @scriptable – cbrulak Oct 28 '15 at 15:58
  • Welcome, See this other [SO answer](http://stackoverflow.com/questions/24003291/ifdef-replacement-in-swift-language) on how to set and use environment variables in xcode. This should help – Scriptable Oct 28 '15 at 15:58
  • saw that. but you can't change the flags at run time. – cbrulak Oct 28 '15 at 15:59
  • then it all depends on how your app is going to decide during runtime which config to use. you could just use a global variable which is an enum of which config to load. you can always switch this value based on values at runtime such as user id or other permissions. A quick and easy method would be to set a value on the appdelegate and also have a function to return the config based on the current value. Sure someone will come along shortly with a more elegant way. – Scriptable Oct 28 '15 at 16:07
  • I think you can add a global variable. And have a place for change when test. Example: if you have login screen with logo. You can define that: when tap 4 times to it. Change it to another environment. – vien vu Oct 28 '15 at 16:50
  • This is more typically done using multiple targets each pointing to a different configuration. If you want to test each config, you should provide a different build for each. Otherwise, you will need to create a UI to switch between them at run time as @ZoffDino pointed out. – Matt Long Oct 28 '15 at 17:51

0 Answers0