Last active
December 11, 2019 06:30
-
-
Save dubemike/99f952d217090889e6e5ee7e0da3a2f4 to your computer and use it in GitHub Desktop.
A lightweight enum based Feature flag system
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 FeatureFlag: String, CaseIterable { | |
case featureOne | |
} | |
extension FeatureFlag { | |
var isEnabled: Bool { | |
switch self { | |
case .featureOne: | |
if isRunningInAppStore() { | |
return false | |
} | |
return featureFlagValue() | |
} | |
} | |
private var key: String { | |
return "com.companyname.featureflag." + rawValue | |
} | |
private func featureFlagValue() -> Bool { | |
return UserDefaults.standard.bool(forKey: key) | |
} | |
func enable() { | |
UserDefaults.standard.set(true, forKey: key) | |
} | |
func disable() { | |
UserDefaults.standard.set(false, forKey: key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment