Let's assume function calculate() takes 30 seconds to return an int
calculate() -> Int{
let anInt = ...//task that takes 30 seconds to complete
return anInt
}
If I am using if let to conditionally bind the value of calculate to a variable like below:
if let theIntIWant = calculate() as? String {
print("the value I want is: \(theIntIWant)")
}
Will this if let function similarly to a closure, where theIntIWant will not be evaluated until calculate() returns its value? I am trying to understand when I need to use a closure for asynchronous tasks and am not sure I would need it in this case.
Aucun commentaire:
Enregistrer un commentaire