Skip to content

Instantly share code, notes, and snippets.

@Ravi61
Created July 13, 2017 18:42
Show Gist options
  • Save Ravi61/e4529b9c600139530c6bd3cbaa5772df to your computer and use it in GitHub Desktop.
Save Ravi61/e4529b9c600139530c6bd3cbaa5772df to your computer and use it in GitHub Desktop.
Model for Dictionary decoding
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