Skip to content

Instantly share code, notes, and snippets.

@reeichert
Created May 17, 2017 13:41
Show Gist options
  • Save reeichert/6f9f8632ca34bf51e70ee23413628734 to your computer and use it in GitHub Desktop.
Save reeichert/6f9f8632ca34bf51e70ee23413628734 to your computer and use it in GitHub Desktop.
Should show tutorial
public class AppManager: NSObject {
static let userDefaults = UserDefaults.standard
static let shared = AppManager()
static let dataKey = "AppManagerDataKey"
static let tutorialKey = "AppManagerTutorialKey"
public func reset(for key: String) {
if var data = userDefaults.object(forKey: dataKey) as? [String: Bool] {
data.removeValue(forKey: key)
userDefaults.set(data, forKey: dataKey)
}
}
public func shouldShowTutorial() -> Bool {
if var data = userDefaults.object(forKey: dataKey) as? [String: Bool] {
if let _ = data[tutorialKey] {
return false
}
data[tutorialKey] = true
userDefaults.set(data, forKey: dataKey)
return true
}
let data = [tutorialKey: true]
userDefaults.set(data, forKey: dataKey)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment