@ObservableObject and NSManagedObject

Can I use NSManagedObject with @ObservableObject and @Published to auto-reconfigure my collection view's cells?

Accepted Reply

Yes, though I would drive a collection view with an NSFetchedResultsController and bindings.

NSManagedObject subclasses are automatically observable. You don't need to do anything for ObservableObject conformance, nor do you need to annotate properties with @Published. In SwiftUI views, you can just add an @ObservedObject var for your managed object, and the view tracks as properties and relationships of that object update.

Add a Comment

Replies

Yes, though I would drive a collection view with an NSFetchedResultsController and bindings.

NSManagedObject subclasses are automatically observable. You don't need to do anything for ObservableObject conformance, nor do you need to annotate properties with @Published. In SwiftUI views, you can just add an @ObservedObject var for your managed object, and the view tracks as properties and relationships of that object update.

Add a Comment