Is there a way to pass an inout parameter through a scheduledTimer method? I want a specific value(disable Button until timer has run out).
func Timer(Hz:TimeInterval, Activate: inout Bool, time:Double=10){
let info = ProcessInfo.processInfo
let begin = info.systemUptime
var A=0
// do something
var diff = (info.systemUptime - begin)
print("Time runs\n")
let timer=Timer.scheduledTimer(withTimeInterval: Hz, repeats: true) { timer in
diff=(info.systemUptime - begin)
if (diff>=time){
timer.invalidate()
print("Finished")
Activate = !Activate
A=1
}
}
if (A==1){
print("Will never happen")
}
}
Var A is just there to show that I also tried a different approach but it didn't work
If the button is a reference type (ie, a class), which it will be if it's a UIKit or AppKit type, you can just pass it in, but there's a more general way of doing that is maybe better. Pass a closure in to act as a completion handler:
Then you can disable the button like this: