Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension KeyedDecodingContainer {
func decode<T: NSCoding>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> T? {
let data = try decode(Data.self, forKey: key)
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T ?? nil
}
}
extension KeyedEncodingContainer {
mutating func encode(_ value: NSCoding, forKey key: KeyedEncodingContainer<K>.Key) throws {
let data = NSKeyedArchiver.archivedData(withRootObject: value)
try encode(data, forKey: key)
}
}
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.