for example, I have a variable X = 0 , I have to call the getStatus() method that sends a request to the server and updates the variable Y , and while X == Y I re-send a request to the server every 2 seconds for 10 seconds, if for example during some of their requests, came Y = 1 , that is, Y != X - I stop the cycle and stop sending requests, if after 10 seconds they are still equal, I will show an alert.
I tried to do this, but the method is not suitable, since the cycle is processed instantly, and the methods in memory are invoked on a timer, but they remember the old one, not updated by one of the Y requests:
func valueInspection() { var time = 2 for _ in 1...10 { if x == y { time += 2 _ = Timer.scheduledTimer(timeInterval: TimeInterval(time), target: self, selector: #selector(General.getStatus), userInfo: nil, repeats: false) } else { print ("VALUE CHANCHED") } } }
getStatus()if do not match, stop the timer? - VAndrJgetStatus()when retrieving data, the value of perpertyYchanges. By clicking on the button, I send a request to the server to change the variableY, callvalueChange(), and call thevalueChange()state checking method, change it or not, about which the actual question is pbogdanv