Created
November 7, 2020 12:47
-
-
Save anoop4real/bea9d3f11e0b0a34924b6b3779f8cd9b to your computer and use it in GitHub Desktop.
FeatureFlags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Environment { | |
case dev | |
case qa | |
case prod | |
} | |
enum FeatureType { | |
case feature1 | |
case feature2 | |
func isFeatureEnabledFor(environment: Environment) -> Bool { | |
switch environment { | |
case .dev: | |
switch self { | |
case .feature1: | |
return true | |
case .feature2: | |
return true | |
} | |
case .qa: | |
switch self { | |
case .feature1: | |
return true | |
case .feature2: | |
return false | |
} | |
case .prod: | |
switch self { | |
case .feature1: | |
return false | |
case .feature2: | |
return true | |
} | |
} | |
} | |
} | |
class MyClass { | |
let currentEnvironment = Environment.prod | |
func check() { | |
if(FeatureType.feature1.isFeatureEnabledFor(environment: currentEnvironment)) { | |
print("Do something") | |
} else { | |
print("Use existing flow") | |
// Use existing flow | |
} | |
if(FeatureType.feature2.isFeatureEnabledFor(environment: currentEnvironment)) { | |
print("Do something") | |
} else { | |
// Use existing flow | |
print("Use existing flow") | |
} | |
} | |
} | |
let myClass = MyClass() | |
myClass.check() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment