Post

Replies

Boosts

Views

Activity

Reply to Repeating function in SwiftUI
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
Aug ’23