Oddbean new post about | logout
 Has anyone used the new @​Observable property alongside Codable? I get warnings that it won't be decoded because it's declared with an initial value, but I don't see how that's the case. 

Are Observable and Codable not compatible?

https://files.mastodon.social/media_attachments/files/111/127/407/843/834/791/original/86da222bcdc31f04.png 
 @096d2c53 Observable implies Identifiable, right? If there’s no explicit Identifiable conformance, it probably adds a ‘let id = UUID()’ in the background. That (or something like it) is likely to be what Codable is complaining about. 
 @096d2c53 you can ignore the warning and everything will encode/decode fine, but you’ll get some extra properties like _observationRegistrar synthesized automatically which isn’t nice… seems like manually conforming is the best option 🫤 
 @096d2c53 i believe this is because @Observable is a macro that expands your code and (invisible to you) creates an “observationRegistrar” constant. 
 @096d2c53 if you expand the macro in Xcode, you can see where the error is actually coming from:

https://files.mastodon.social/media_attachments/files/111/127/509/718/651/631/original/c62628c63db93a4c.png 
 It seems the play then is to manually implement init(decoder:)

But then when initing the values, do I want to set the "secret" self._favIceCreams that the macro defined? Or the "regular" self.favIceCreams? Swift autocompletes the former but the latter feels more correct?