typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "response", intValue: nil)], debugDescription: "Expected to decode Dictionary<String, Any> but found an array instead.", underlyingError: nil))
Всем привет, через раз выдаёт ошибку: The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions Как фиксить?
// MARK: - Welcome struct Welcome: Codable { let success: String let response: [Response] }
// MARK: - Response struct Response: Codable { let amount: Amount let currency: String? let created: Int let desc: String }
enum Amount: Codable { case double(Double) case string(String)
init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() if let x = try? container.decode(Double.self) { self = .double(x) return } if let x = try? container.decode(String.self) { self = .string(x) return } throw DecodingError.typeMismatch(Amount.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for Amount")) }
func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() switch self { case .double(let x): try container.encode(x) case .string(let x): try container.encode(x) } } }