Created
July 16, 2019 13:42
-
-
Save HassanElDesouky/373bcf4f1002f77557814a3e24fa4759 to your computer and use it in GitHub Desktop.
Revisions
-
HassanElDesouky created this gist
Jul 16, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ extension UserDefaults { func colorForKey(key: String) -> UIColor? { var colorReturnded: UIColor? if let colorData = data(forKey: key) { do { if let color = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(colorData) as? UIColor { colorReturnded = color } } catch { print("Error UserDefaults") } } return colorReturnded } func setColor(color: UIColor?, forKey key: String) { var colorData: NSData? if let color = color { do { let data = try NSKeyedArchiver.archivedData(withRootObject: color, requiringSecureCoding: false) as NSData? colorData = data } catch { print("Error UserDefaults") } } set(colorData, forKey: key) } }