Post

Replies

Boosts

Views

Activity

Reply to XCode 26.0.1/iOS 26 unable to mark class as ObservableObject
'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"?
Oct ’25
Reply to XCode 26.0.1/iOS 26 unable to mark class as ObservableObject
'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"?
Replies
Boosts
Views
Activity
Oct ’25
Reply to XCode 26.0.1/iOS 26 unable to mark class as ObservableObject
Update: I realized two changes to fix the problems: I have to import Combine and CoreData in my DataController.swift (before only CoreData) 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
Replies
Boosts
Views
Activity
Oct ’25