XCode 26.0.1/iOS 26 unable to mark class as ObservableObject

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.

Answered by DTS Engineer in 860857022

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"

Just so we’re clear, ObservableObject isn’t part of Observation but part of Combine.

I tried this out here in my office:

  1. Using Xcode 26.0.1, I created a new project from the macOS > Command Line Tool template.

  2. I changed main.swift to this code:

    import Combine
    
    class XYZ: ObservableObject {
    }
    
  3. I chose Product > Build and it compiled just fine.

I’m not sure what’s going on in your case but it’s clearly context dependent. My advice is that you repeat the above steps to see if you can get the basics working. After that you can then explore why your original project is behaving differently from this test project.

after updating to 26.0.1

Upgrading from what? Xcode 26.0? Or Xcode 16.4?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

'Error' occurred after updgrading from 16.4 to 26

Importing combine solves the problem of an empty class XYZ: ObservableObject

When using CoreData in a Swift App, I was used to have a Class 'DataController : ObservableObject' to manage the CoreData Stack. In the past I was used to only import CoreData and everything works fine:

//
//  Observable Object to enable Access to CoreData within the App
//  therefore include in @main:
//  ... 1. @StateObject var dataController = DataController()
//  ... 2. ContentView()
//              .environment(\.managedObjectContext, dataController.container.viewContext)
//              .environmentObject(dataController)

import CoreData

class DataController: ObservableObject {
    let container: NSPersistentCloudKitContainer

    init() {
        container = NSPersistentCloudKitContainer(name: "Main")

        container.loadPersistentStores { storeDescription, error in
            if let error {
                 fatalError("Fatal error loading store: \(error.localizedDescription)")
            }
        }
    }

    // DO some stuff here

    func save() {
        if container.viewContext.hasChanges {
            try? container.viewContext.save()
        }
    }
...
}

Now I have to import Combine and add Protocol stubs to get rid of the error. Something must have change "under the hood of Xcode"?

Update: I realized two changes to fix the problems:

  1. I have to import Combine and CoreData in my DataController.swift (before only CoreData)
  2. I have to import SwiftUI and CoreData in my xyzAPP.swift (containing @main) (before only SwiftUI).

=> Looks like we have to import a lot more nowadays

Accepted Answer

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"

XCode 26.0.1/iOS 26 unable to mark class as ObservableObject
 
 
Q