-
-
Save Pasanpr/16c371aaf62dbdff7918eb57f6eea333 to your computer and use it in GitHub Desktop.
Starter code for S2:V1 - Parsing Dates
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 = """ | |
{ | |
"title": "Harry Potter and the sorcerer's stone", | |
"url": "https:\\/\\/openlibrary.org\\/books\\/OL26331930M\\/Harry_Potter_and_the_sorcerer's_stone", | |
"publish_date": "1997-06-26T00:00:00+0000", | |
"text": "VGhpcyBpc24ndCByZWFsbHkgdGhlIGNvbnRlbnRzIG9mIHRoZSBib29r", | |
"rating": 4.9 | |
} | |
""".data(using: .utf8)! | |
struct Book: Codable { | |
let title: String | |
let url: String | |
let publishDate: String | |
} | |
let decoder = JSONDecoder() | |
decoder.keyDecodingStrategy = .convertFromSnakeCase | |
let potter = try! decoder.decode(Book.self, from: json) | |
potter.title | |
potter.url | |
potter.publishDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment