Last active
July 21, 2016 12:35
-
-
Save MarioIannotta/80c0522ef82ea1dc57a8b8c305aa455a to your computer and use it in GitHub Desktop.
Smooth NSUserDefault handling with Swift
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 MIUserDefault: String { | |
case persistentStuffOne = "persistentStuffOne" | |
case persistentStuffTwo = "persistentStuffTwo" | |
case persistentStuffThree = "persistentStuffThree" | |
func set(object: AnyObject) { | |
NSUserDefaults.standardUserDefaults().setObject(object, forKey: self.rawValue) | |
} | |
func get() -> AnyObject? { | |
return NSUserDefaults.standardUserDefaults().objectForKey(self.rawValue) | |
} | |
func remove() { | |
NSUserDefaults.standardUserDefaults().removeObjectForKey(self.rawValue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment