Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import Foundation
struct Person: Codable {
let name: String
}
let person = Person(name: "Soroush")
let archiver = NSKeyedArchiver(forWritingWith: NSMutableData())
try archiver.encodeEncodable(person, forKey: "person")
let data = archiver.encodedData
let unarchiver = NSKeyedUnarchiver(forReadingWith: data)
let person2 = unarchiver.decodeDecodable(Person.self, forKey: "person")
person2?.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment