Skip to content

Instantly share code, notes, and snippets.

@Pasanpr
Created March 28, 2018 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pasanpr/47523a0eb9960c15ea6184ea8cf294b2 to your computer and use it in GitHub Desktop.
Save Pasanpr/47523a0eb9960c15ea6184ea8cf294b2 to your computer and use it in GitHub Desktop.
Starter Code for S4:V3 - Decoding to a Class
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