问题
Not able to figure why my class does not conform to Codable Please not that in my case I do not need to implement the methods encode and decode.
public class LCLAdvantagePlusJackpotCache: Codable {
public let token: String
public let amount: NSNumber
public let member: Bool
public init(token: String, amount: NSNumber, member: Bool) {
self.token = token
self.amount = amount
self.member = member
}
enum CodingKeys: String, CodingKey {
case token, amount, member
}
}
回答1:
It's because NSNumber is not Codable. Do not use Objective-C types; use Swift types. (That's a general rule; it isn't confined to the Codable situation. But this is a good example of why the rule is a good one!)
Change NSNumber to Int or Double (in both places where it occurs in your code) and all will be well.
来源:https://stackoverflow.com/questions/50609501/codable-does-not-conform-to-protocol-decodable