-
-
Save Pasanpr/47523a0eb9960c15ea6184ea8cf294b2 to your computer and use it in GitHub Desktop.
Starter Code for S4:V3 - Decoding to a Class
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 | |
let json = """ | |
{ | |
"id": "ABCD", | |
"title": "Some Title" | |
} | |
""".data(using: .utf8)! | |
class Media: Codable { | |
let id: String | |
let title: String | |
} | |
let decoder = JSONDecoder() | |
let encoder = JSONEncoder() | |
encoder.outputFormatting = .prettyPrinted | |
let media = try! decoder.decode(Media.self, from: json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment