6

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
    }

}
Kazunori Takaishi
  • 2,268
  • 1
  • 15
  • 27

1 Answers1

16

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141