Skip to content

Instantly share code, notes, and snippets.

@anoop4real
Created November 7, 2020 12:47
Show Gist options
  • Save anoop4real/bea9d3f11e0b0a34924b6b3779f8cd9b to your computer and use it in GitHub Desktop.
Save anoop4real/bea9d3f11e0b0a34924b6b3779f8cd9b to your computer and use it in GitHub Desktop.
FeatureFlags
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