Swift 4, Codable json decode/encode - Cannot assign to value: 'self' is immutable
Using Stanford CS193P Developing iOS 11 Apps with Swift. Lecture 14. Persistence and Documents Demo , I was able to make my objects Codable
The saving part work, I can see the resulting json in Apple File App
but when I try to read the file with
init?(json: Data) {
if let newValue = try? JSONDecoder().decode(CADevice.self, from: json){
self = newValue
}else{
return nil
}
}
I get an error at compile time
self = newValue -> Cannot assign to value: 'self' is immutable
what should I be looking for ?
Thank you