I'm trying to encode a custom class so I can save it using NSKeyedArchiver.archivedDataWithRootObject
but when I try to conform to the NSCoding protocol, I get this error : 'self' used before self.init. Here is my code:
class MemberRewardsInfo: NSObject, NSCoding {
var id: Int?
required convenience init?(coder aDecoder: NSCoder) {
guard let unarchivedId = aDecoder.decodeObjectForKey("id") as? Int
else {
return nil
}
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(id, forKey: "id")
}
}
its pretty annoying, not sure why it's not working.