Created
April 21, 2016 20:59
-
-
Save joshavant/92201fc050c0f160eeec3dcce8a67faf to your computer and use it in GitHub Desktop.
RawRepresentable, meet NSCoding
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 RawRepresentable where Self: NSCoding { | |
init?(rawValue: NSData) { | |
if let instance = NSKeyedUnarchiver.unarchiveObjectWithData(rawValue) as? Self { | |
self = instance | |
} else { | |
return nil | |
} | |
} | |
var rawValue: NSData { | |
get { | |
return NSKeyedArchiver.archivedDataWithRootObject(self) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment