Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
}
}
@D-32

This comment has been minimized.

Copy link

@D-32 D-32 commented Jan 7, 2017

@vidhyapathipathi

This comment has been minimized.

Copy link

@vidhyapathipathi vidhyapathipathi commented Jul 30, 2018

it's not working for me

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.