Swift NSUserDefaults UIColor extension
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) | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
it's not working for me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Swift 3 version: https://gist.github.com/D-32/d30482e7fa10b6158e69610335052752