I have a view in which i call @FetchRequest as below
@FetchRequest(entity: Sales.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Sales.dateToday, ascending: true)]) var mySales: FetchedResults<Sales>
I then call a delete function that delets all sales data in some different view
.alert(isPresented: $deleteData) {
Alert(title: Text("Are you sure you want to delete all data?"), primaryButton: .destructive(Text("Delete")) {
dataController.shouldReloadData = true <------------toggle the observed property
deleteAll()
dataController.save()
}, secondaryButton: .cancel())
Now i do have a property in my DataController called
@Published var shouldReloadData = false
which i toggle here as you can see, but the when i go back to the view with
@FetchRequest(entity: Sales.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Sales.dateToday, ascending: true)]) var mySales: FetchedResults<Sales>
it does. not show the data as deleted , it is still there, how can i over come this?
Note - the data is gone once the app is sent to back ground and then opened again. so the data is deleted but the fetchrequest is not refreshed.