Last active
May 13, 2021 07:54
-
-
Save artturijalli/87030c62f4c580da62097fdf51c5e066 to your computer and use it in GitHub Desktop.
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
struct Video: Decodable { | |
let title: String | |
} | |
let JSON = """ | |
[{ | |
"title": "JSON Made Simple", | |
"url": "www.example.com/json_data" | |
}, | |
{ | |
"title": "Learn Swift Arrays", | |
"url": "www.example.com/arrays_swift" | |
}, | |
{ | |
"title": "Understanding Swift Dictionaries", | |
"url": "www.example.com/swift_dictionaries" | |
}] | |
""" | |
let jsonData = JSON.data(using: .utf8)! | |
let videos: [Video] = try! JSONDecoder().decode([Video].self, from: jsonData) | |
print(videos.forEach { print($0.title) }) // -> Prints out all the video titles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment