When a SwiftUI View is presented that uses @FetchRequest
and an update occurs while it is presented, it forever retains the backing SwiftUI.FetchController
.
This is a problem if you go to remove the persistent stores as creating a new persistent store and having changes on that will crash the outstanding fetch controller that has stale assets.
- Tap "Open SwiftUI View" (At this point observe in memory debugger that 1 instance of SwiftUI.FetchController exists without a retain cycle)
- Tap "Add new person" in sheet (Now that same object exists but now has a retain cycle)
- Dismiss the sheet by swiping down
- Tap Clear DB (wait for "Persistent stores reloaded" in console)
- Tap "Open SwiftUI View"
- Tap "Add new person" in sheet (Observe Core Data throwing an exception)
Before Adding Entity | After Adding Entity |
---|---|