Started a new X-Code Project after updating to 26.0.1 and realized that I get an error when trying to mark a class as ObservableObject => "Class XYZ does not conform to Protocol 'ObservableObject'.
Strange behaviour, because at old projects the code is working even though the build options are the same and other settings like iOS version in Target are the same.
There must be something chaged under the hood of XCode? I have to import Combine now, before I could write my class, e.g. CoreData Datamanager: ObservableObject only using CoreData.
Well, that’s interesting. I again tried replicating this problem and everything worked for me. But then I tried again in an macOS > App target and I did see the problem. At that point I started digging…
It turns out that I made a mistake in my previous post:
I created a new project from the macOS > Command Line Tool template.
I didn’t use the macOS > Command Line Tool template, but rather I used my own personal template. Once I retesting with the built-in macOS > Command Line Tool template, I saw the problem immediately.
And that give me a working and a non-working case to compare. And doing that I found that this behaviour is gated by the Member Import Visibility build setting. That’s set in the built-in template and not set in my personal template. And with it set I see the error compiling DataController
and with it unset I don’t.
This build setting is a product of a recent Swift Evolution change, namely SE-0444 Member import visibility. I’m not really an expert on that, but it’s not hard to see how it might trigger an issue like this. The original declaration for ObservableObject
is in Combine, so using it without importing Combine puts you on thin ice.
So, yeah, I think the right answer here is to import what you use. If you rely on ObservableObject
, import Combine.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"