'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"?
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags: