Slide 51
Slide 51 text
༻ํ๏
let farm = Farm(name: "Old MacDonald's Farm",
location: Location(latitude: 51.621648,
longitude: 0.269273),
animals: [.chicken, .dog, .cow, .turkey,
.dog, .chicken, .cow, .turkey, .dog])
let payload: Data = try JSONEncoder().encode(farm) // 1
do {
let farm = try JSONDecoder().decode(Farm.self, from: payload) // 2
// Extracted as user types:
let coordinates = "\(farm.location.latitude, farm.location.longitude)"
} catch {
// Encountered error during deserialization
}
SE-0166