I have a UIView with a list of items. When one item is deleted from the list an overall variable will be recalculated in the model class, which will take some time as it will go over all data on all the items. In order to keep in touch with the user I like to show a progress bar, but for that I need the percentage done from the class to the UIView. I was not able to find out how to get the percentage during the recalculation. I would be very happy if one could point me to the right direction:
my UIView shorted:
var body: some View {
List{
ForEach(handicapValues, id:.self) {handicapValue in
NavigationLink(value:handicapValue,
label: {CellRoundView(handicapValue: handicapValue)})
.padding(.bottom, 1)
.swipeActions(allowsFullSwipe: false) {
Button() {
itemToDelete = handicapValue
showingRecalc = true
} label: {
Label("Delete", systemImage: "trash.fill")
}
.tint(.red)
} // End of .swipeActions()
} // end foreach
}.alert(isPresented: $showingRecalc) {
Alert(title: Text("Delete round ?"), message: Text("Handicaps will be recalculated"), primaryButton: .destructive(Text("Delete")) {
removeRound(hcValue: itemToDelete!)
PersistentController.shared.recalcHCvalues_test(rounds: rounds, loops: loops, handicapValues: handicapValues)
userData.myHandicap = round(10*handicapValues[handicapValues.count-1].whsHC)/10
},
secondaryButton: .cancel())
}
It is in the PersistentController Class that I do the calculations for item in items. I know the total number of items so it is easy to calculated the percentage done. What I need is: bring this value back to the UIView to support a progress bar for the user to not get impatient.