swift - Does using IF LET act like closure -
let's assume function calculate() takes 30 seconds return int
update/edit: neglected mention let's assume on background thread , not main thread.
calculate() -> int{ let anint = ...//task takes 30 seconds complete return anint }
if using if let
conditionally bind value of calculate variable below:
if let theintiwant = calculate() as? string { print("the value want is: \(theintiwant)") }
will if let
function closure, theintiwant not evaluated until calculate()
returns value? trying understand when need use closure asynchronous tasks , not sure need in case.
this has nothing closures, nor have said calculate
being asynchronous. nor has if let
! question has threads.
the rules simple enough. must not block main thread length of time. if calculate()
has ability return value after 30 seconds of work, must called only on background thread. if, having called it, want result involves properties, interface, or other non-threadsafe things, need onto main thread.
Comments
Post a Comment