Last active
July 7, 2016 19:32
-
-
Save dornad/38b99aac81744d716a49864589899dd5 to your computer and use it in GitHub Desktop.
NSUserDefaults
This file contains 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
@objc public enum Features: Int { | |
case ScheduledSendingCoachmark = 0 | |
case AccountVerifyFailureToggle | |
} | |
extension Features { | |
private var userDefaultsKey: String { | |
switch(self) { | |
case .ScheduledSendingCoachmark: | |
return NSUserDefaults.Keys.ScheduledSendingCoachmark | |
case .AccountVerifyFailureToggle: | |
return NSUserDefaults.Keys.AccountVerifyFailureToggle | |
} | |
} | |
extension NSUserDefaults { | |
private struct Keys { | |
static let ScheduledSendingCoachmark = "ScheduledSendingCoachmark" | |
static let AccountVerifyFailureToggle = "AccountVerifyFailureToggle" | |
} | |
public func shown(feature feature:Features) -> Bool { | |
return bool(forKey: feature.userDefaultsKey) | |
} | |
public func save(feature feature:Features, value: Bool = true) { | |
setBool(value, forKey: feature.userDefaultsKey) | |
synchronize() | |
} | |
public func dbg_reset(feature feature:Features) { | |
save(feature:feature, value: false) | |
} | |
} | |
> Usage | |
let appGroup = NSUserDefaults(suiteName: "name of app group") | |
let standard = NSUserDefaults.standardUserDefaults() | |
print( appGroup.shown(feature: .ScheduledSendingCoachmark) ) // return false... | |
print( standard.shown(feature: .ScheduledSendingCoachmark) ) // return false... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment