Created
August 15, 2018 10:39
-
-
Save samjarman/8b4ef1ad60b74e1e0ec3622762531b26 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
$curl http://pokeapi.co/api/v2/pokemon/?limit=3 | |
// Models... | |
struct PokemonListResult: Codable { | |
let count: Int? | |
let previous: URL? | |
let results: [PokemonIndex]? | |
let next: URL? | |
} | |
struct PokemonIndex: Codable { | |
let name: String? | |
let detailsURL: URL? | |
private enum CodingKeys: String, CodingKey { | |
case name | |
case detailsURL = "url" | |
} | |
} | |
// In DataTask callback... | |
do { | |
let decoder = JSONDecoder() | |
let pokemans = try decoder.decode(PokemonListResult.self, from: data) | |
print(pokemans) | |
delegate.didSuccessfullyFetchPokemonList(withList: pokemans.results!) | |
} catch let err { | |
print("Err", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment