Forked from aclissold/NSUserDefaults+UIColor.swift
Last active
August 29, 2015 14:24
-
-
Save sidpagariya/64835ffffe768ee5be6c to your computer and use it in GitHub Desktop.
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
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