Issue #623
Listen to context changes notification and change SwiftUI View state
let changes = [NSDeletedObjectsKey: ids]
NSManagedObjectContext.mergeChanges(
fromRemoteContextSave: changes,
into: [context]
)
try context.save()
struct ListView: View {
@Environment(\.managedObjectContext)
var context
private var didSave = NotificationCenter.default.publisher(for: .NSManagedObjectContextDidSave)
@State
private var refreshing: Bool = false
var body: some View {
makeContent()
.onReceive(didSave) { _ in
self.refreshing.toggle()
}
}
}
We need to actually use that State variable for it to have effect
if refreshing {
Text("")
} else {
Text("")
}