When deleting a core data object that is an @ObservedObject in a SwiftUI View, the app will crash because of the "createdAt" date property.
FeedbackID: FB9750936
Stack Overflow Post: https://stackoverflow.com/questions/69917937/observed-object-core-data-deletion-crashes-app
System Info:
- Xcode 13.1 (13A1030d)
- iPad Air 4th Generation (iOS 15.0 Simulator)
- iPad Pro 11 (2018, iOS 15.1)
Reproduction steps:
- Run app on iPad in landscape
- Tap the plus button on the sidebar toolbar to add "Item" data
- Select the "Item" you just created
- On the details screen, swipe to delete any of the subItems.
Actual Results: App crashes and directs you to the following line in the SubItemsViewRow file:
"Text(subItem.createdAt.formatted())"
Expected Results: SubItem deletes successfully and the row animates away.
Individual Work Arounds:
- Change the SubItem createdAt property to be optional.
- Add a delay (< ~0.7 seconds) between the core data deletion and save.