Last active
May 10, 2020 20:17
-
-
Save angelinaFri/0fcaea5ee086798bde383cd7f8aa41fd 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
import Foundation | |
// MARK: - TeamPlayersResponse | |
struct TeamPlayersResponse: Codable { | |
let copyright: String | |
let roster: [Roster] | |
let link: String | |
} | |
// MARK: - Roster | |
struct Roster: Codable { | |
let person: Person? | |
let jerseyNumber: String? | |
let position: Position? | |
public init(from decoder: Decoder) throws { | |
let values = try decoder.container(keyedBy: CodingKeys.self) | |
person = try values.decodeIfPresent(Person.self, forKey: .person) | |
jerseyNumber = try values.decodeIfPresent(String.self, forKey: .jerseyNumber) | |
position = try values.decodeIfPresent(Position.self, forKey: .position) | |
} | |
} | |
// MARK: - Person | |
struct Person: Codable { | |
let id: Int | |
let fullName, link: String | |
} | |
// MARK: - Position | |
struct Position: Codable { | |
let code: String? | |
let name: String? | |
let type: String? | |
let abbreviation: String? | |
public init(from decoder: Decoder) throws { | |
let values = try decoder.container(keyedBy: CodingKeys.self) | |
code = try values.decodeIfPresent(String.self, forKey: .code) | |
name = try values.decodeIfPresent(String.self, forKey: .name) | |
type = try values.decodeIfPresent(String.self, forKey: .type) | |
abbreviation = try values.decodeIfPresent(String.self, forKey: .abbreviation) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment