Created
September 3, 2017 20:03
-
-
Save khanlou/f1185668ed37eb420db32a1f4d582242 to your computer and use it in GitHub Desktop.
This file contains 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
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