Created
July 13, 2017 18:42
-
-
Save Ravi61/e4529b9c600139530c6bd3cbaa5772df to your computer and use it in GitHub Desktop.
Model for Dictionary decoding
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 Spaceship: Codable { | |
var model: String | |
var movie: String | |
} | |
//... | |
let jsonDecoder = JSONDecoder() | |
do { | |
let spaceships = try jsonDecoder.decode([String: Spaceship].self, from: jsonData!) | |
spaceships.forEach({ print("\($0.key): \($0.value)") }) | |
} catch { | |
print("parse error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment