user4422315
user4422315

Reputation:

Codable : does not conform to protocol 'Decodable'

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
    }

}

Upvotes: 7

Views: 7591

Answers (1)

matt
matt

Reputation: 534885

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.

Upvotes: 18

Related Questions