Data Tracking and Notifications in Core Data and SwiftData
[
prepareForDeletion
is called] when the managed object is about to be deleted, typically used for cleaning up resources or manually managing relationships. Note that this method is triggered beforevalidateForDelete
. If the deletion operation fails due to validation failure, changes made in this method may be rolled back.[…]
However, because these operations are extensions of managed object subclasses, if you don’t build subclasses or don’t operate through specific types, these methods won’t be called. For example, during batch operations, specific managed object subclasses are usually not involved, so these lifecycle methods won’t be called.
Although SwiftData’s default storage implementation is based on Core Data, it doesn’t declare managed object subclasses for each entity. Therefore, SwiftData doesn’t provide similar functionality—these notification timings are unique to Core Data.
[…]
Unlike context notifications, [Persistent History Tracking] or SwiftData History doesn’t include specific change information in the notification. Developers need to retrieve changes that occurred after a specific time from the database through code to obtain this data.
Previously:
- Returning to Core Data
- SwiftData and Core Data at WWDC24
- Turning Off Core Data Persistent History Tracking
- SwiftUI Data Flow 2023
- Persistent History Tracking in Core Data
1 Comment RSS · Twitter · Mastodon
Well, it’s only a 2.0 product that has been released just two years ago. You can’t expect anything but the most shallow of WWDC examples. Coincidentally SwiftUI is now, what, six years old, and still is still at the same facepalmable state. The developer tools are in this state for 11 years.
I wonder what it is. Is it the shallow generation that works currently for Apple; is it the management who doesn’t demand quality from their employees; is it that large portions of these engineers prefers to be identity politician snowflakes on social media, doing performative hysteria all day. It’s definitely an industry-wide phenomenon. Windows 11 is a complete mess, and while I cannot speak to the quality at the API and framework level, the OS itself, from design, performance or functionality, is completely bankrupt.