Skip to content

Instantly share code, notes, and snippets.

@khanlou
Created September 3, 2017 20:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanlou/f1185668ed37eb420db32a1f4d582242 to your computer and use it in GitHub Desktop.
Save khanlou/f1185668ed37eb420db32a1f4d582242 to your computer and use it in GitHub Desktop.
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