Sad to see nobody has a answer for this. Did you ever find a solution for this issue?
Post
Replies
Boosts
Views
Activity
Here's how to make the loop stop:
By using a @State variable
struct ContentView: View {
@State var stop: Bool = false
var body: some View {
Text("keep calling a function")
.padding()
.onAppear {
callFunc()
}
.onTapGesture{
if stop { //Continue loop
stop = false
callFunc()
} else { //Stop loop
stop = true
}
}
}
func callFunc() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
print("-----> callFunc")
if !stop {
callFunc()
}
}
}
}
Brendan Okey-Iwobi