Created
          June 1, 2015 14:52 
        
      - 
      
 - 
        
Save aclissold/eaa3ef99e211bee76a58 to your computer and use it in GitHub Desktop.  
    Swift NSUserDefaults UIColor extension
  
        
  
    
      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
  
            
Swift 3 version: https://gist.github.com/D-32/d30482e7fa10b6158e69610335052752