Permalink
Find file Copy path
0d10160 Oct 23, 2017
1 contributor

Users who have contributed to this file

25 lines (17 sloc) 541 Bytes
//: Playground by Ihor Malovanyi & justDev team. Enjoy, my friend
import UIKit
struct Person: Codable {
var firstName: String
var lastName: String
}
struct Flight : Codable {
var name: String
var pilot: Person
}
let pilot = Person(firstName: "James", lastName: "Cameron")
let flight = Flight(name: "Boeing 777", pilot: pilot)
let data = try? JSONEncoder().encode(flight)
if let string = String(data: data!, encoding: .utf8) {
print(string)
}
let decodedFlight = try? JSONDecoder().decode(Flight.self, from: data!)