[ad_1]
I’ve a operate in my SwiftUI app that waits 0.5 seconds for the entire information to return in after which rearranges the order of a listing based mostly on that information. This ultimately works, however it makes for some bizarre leaping round for the primary second or so of the checklist order as a result of it’s being modified after 0.5 seconds. The code seems like this:
DispatchQueue.most important.asyncAfter(deadline: .now() + 0.5) {
self.eating places.type {
let waitTime1 = self.waitTimes[$0.id!] ?? -1
let waitTime2 = self.waitTimes[$1.id!] ?? -1
if (waitTime1 >= 0 && waitTime2 < 0) {
return true
} else if (waitTime1 < 0 && waitTime2 >= 0) {
return false
} else if (waitTime1 >= 0 && waitTime2 >= 0) {
return waitTime1 < waitTime2
} else if (waitTime1 < 0 && waitTime2 < 0) {
return false
} else {
return false
}
}
}
Primarily, I would like wait 0.5 seconds for the self.waitTimes information to return in or else the checklist will type with out it. I need to attempt to present a ProgressView over the common content material view whereas this sorting is happening, for a couple of second. I attempted placing all my content material in a separate content material view after which setting it equal to a ProgressView for a second then setting it again to the unique content material, however this did not work:
contents = AnyView(ProgressView())
DispatchQueue.most important.asyncAfter(deadline: .now() + 0.5) {
contents = AnyView(origContents)
self.eating places.type {
let waitTime1 = self.waitTimes[$0.id!] ?? -1
let waitTime2 = self.waitTimes[$1.id!] ?? -1
if (waitTime1 >= 0 && waitTime2 < 0) {
return true
} else if (waitTime1 < 0 && waitTime2 >= 0) {
return false
} else if (waitTime1 >= 0 && waitTime2 >= 0) {
return waitTime1 < waitTime2
} else if (waitTime1 < 0 && waitTime2 < 0) {
return false
} else {
return false
}
}
}
Does anybody have any options for the way I can have the ProgressView be displayed for a second whereas my checklist will get sorted? Thanks
[ad_2]
