Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension NSUserDefaults {
func colorForKey(key: String) -> UIColor? {
var color: UIColor?
if let colorData = dataForKey(key) {
color = NSKeyedUnarchiver.unarchiveObjectWithData(colorData) as? UIColor
}
return color
}
func setColor(color: UIColor?, forKey key: String) {
var colorData: NSData?
if let color = color {
colorData = NSKeyedArchiver.archivedDataWithRootObject(color)
}
setObject(colorData, forKey: key)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.