Post

Replies

Boosts

Views

Created

Sequential execution of asynchronous functions. How?
Hi How to correctly implement such functionality: There is a function call (They are called in a loop) test1(timeout: 10) test2(timeout: 5) test3(timeout: 1) For me, the correct execution should be like this - first, the first function is executed in 10 seconds, then the second in 5 after the first is completed and similarly the third should start 1 second after the second I tried using DispatchQueue and Timer, but nothing worked for me func test1(timeout: int, completion: @escaping () -> ()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + timeout) { print("finish1") completion() } }) func test2(timeout: int, completion: @escaping () -> ()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + timeout) { print("finish2") completion() } }) func test3(timeout: int, completion: @escaping () -> ()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + timeout) { print("finish3") completion() } }) The start of the execution of functions depends on the time, and I need the functions to be executed sequentially as they were started and the time was responsible for the start of execution, but after her turn came
6
0
2.5k
Aug ’21
Sheet sees the variable change from the second time
Hi everybody, after updating to 14 iOS ran into a problem. When calling Sheet, there is a later update of the variable from the second time. I will give an example: @State var showTestSheet : Bool = false @State var testVar : Bool = false Button(action: { self.testVar.toggle() 		self.showTestSheet = true 			}) { 				 Text("Test") } .sheet(isPresented: self.$showTestSheet, content: { if(self.testVar) { 		 Text("True") } else { 		 Text("False") }}) The first time the button is clicked, the testVar variable changes, but inside sheet it is not changed. When you press the button again, everything works as expected. On iOS 13 everything works without errors. Maybe I'm doing something wrong or I missed the information that something has changed. If anyone comes across, help or tell me where to look. Very grateful in advance for any answer.
5
2
4.9k
Sep ’20