0

I've got five different schemes: Debug, Release, Staging, Production, Testing. I've already set them all up.

I want to change the text of a label and the background color of a view according to the specified schemes.

In AppDelegate I've implemented the following method:

func setDomainEnv() {
        #if Debug
            serverEndPointURL = "www.debug.com"
            var fancyBackgroundColor = UIColor(hue: 0.007, saturation: 0.589, brightness: 0.572, alpha: 1.0)
        #elseif Testing
            serverEndPointURL = "www.testing.com"
            var fancyBackgroundColor = UIColor(hue:0.971, saturation:0.715, brightness:1, alpha:1)
        #elseif Staging
            serverEndPointURL = "www.staging.com"
            var fancyBackgroundColor = UIColor(hue: 0.373, saturation: 0.602, brightness: 0.863, alpha: 1.0)
        #elseif Release
            serverEndPointURL = "www.release.com"
            var fancyBackgroundColor = UIColor(hue: 0.571, saturation: 1.0, brightness: 1.0, alpha: 1.0)
        #elseif Production
            serverEndPointURL = "www.production.com"
            var fancyBackgroundColor = UIColor(hue: 0.66, saturation: 0.516, brightness: 0.871, alpha: 1.0)
        #endif
    }

The method gets called in the application didFinishLaunchingWithOptions method:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        self.setDomainEnv()
        return true
    }

I've also set up a file called Constants which stores my variables:

import Foundation
import UIKit

var serverEndPointURL = "www.apple.com"
var fancyBackgroundColor = UIColor.black

In my ViewController, I use those variables in my viewDidLoad method:

override func viewDidLoad() {
    super.viewDidLoad()
    label.text = serverEndPointURL
    self.view.backgroundColor = fancyBackgroundColor
}

However, the only thing that changes is the text of the label. The background color does not change based on the specified scheme. It is always black (the value stored in the Constants file). it will not change based on the selected scheme. Any ideas?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
WalterBeiter
  • 2,021
  • 3
  • 23
  • 48
  • Did you declare `Production`, `Release` and so on in the Environment Variables (https://stackoverflow.com/questions/29131865/xcode-swift-how-do-i-declare-a-variable-constant-with-different-values-depend) ? – Larme Jul 25 '18 at 13:23
  • Did you add breakpoint in `setDomainEnv()` to see if any of the `#if`s gets triggered? – Ladislav Jul 25 '18 at 13:34

1 Answers1

2

You are defining a new variable fancyBackgroundColor instead of changing the value of the already existing fancyBackgroundColor in the constant file. You should remove the var keyword in setDomainEnv method.

Milander
  • 1,021
  • 11
  • 18