Skip to content

Instantly share code, notes, and snippets.

@homerblr
Created November 24, 2021 16:40
Show Gist options
  • Save homerblr/a2c36fc66ffca664a45fecb585793d16 to your computer and use it in GitHub Desktop.
Save homerblr/a2c36fc66ffca664a45fecb585793d16 to your computer and use it in GitHub Desktop.
some fix for boa
struct NBLLiveBoxScoreTeamTotalCoverAPIModel: Codable {
let team: BoxScoreTeamTypeEnum?
let players: [NBLLiveBoxScoreAPIModel]?
enum BoxScoreTeamTypeEnum: Codable {
case object(NBLLiveBoxScoreTeamAPIModel?)
case array(Array<NBLLiveBoxScoreTeamAPIModel>)
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
do {
self = .array(try container.decode([NBLLiveBoxScoreTeamAPIModel].self))
} catch DecodingError.typeMismatch {
self = .object(try container.decode(NBLLiveBoxScoreTeamAPIModel.self))
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .object(let value):
try container.encode(value)
case .array(let value):
try container.encode(value)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment