Skip to content

Instantly share code, notes, and snippets.

@dubemike
Last active Dec 11, 2019
Embed
What would you like to do?
A lightweight enum based Feature flag system
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