Encode/decode in 3.0

I’m using the following code:

func encodeWithCoder( aCoder: NSCoder) {
if let name = name {
aCoder.encode(name, forKey: “name”)
}
aCoder.encode(raise, forKey: “raise”)
}

required init(coder aDecoder: NSCoder) {
    name = aDecoder.decodeObject(forKey: "name") as! String?
    raise = aDecoder.decodeFloat(forKey: "raise")
    super.init()
}

override init() {
    super.init()
}

and xcode tells me that "type “Emplyee” does not conform to protocol NSCoding"
I sduspect this is a 2.0 ->3.0 problem. HELP!!

marc

The function you need to implement is func encode(with aCoder: NSCoder) instead of func encodeWithCoder( aCoder: NSCoder) . This is according the new Swift 3.x naming convention. Implementation should be the same.