Fix featuredTags weird decode

This commit is contained in:
Thomas Ricouard 2023-01-15 14:21:08 +01:00
parent 6b210aec4f
commit 9e569df417
1 changed files with 16 additions and 0 deletions

View File

@ -41,4 +41,20 @@ public struct FeaturedTag: Codable, Identifiable {
public var statusesCountInt: Int {
Int(statusesCount) ?? 0
}
private enum CodingKeys: String, CodingKey {
case id, name, url, statusesCount
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
name = try container.decode(String.self, forKey: .name)
url = try container.decode(URL.self, forKey: .url)
do {
statusesCount = try container.decode(String.self, forKey: .statusesCount)
} catch DecodingError.typeMismatch {
statusesCount = try String(container.decode(Int.self, forKey: .statusesCount))
}
}
}