-2

I have used completionHandler in my Application as follows

fun getDetails(completionHandler: (variable: AnyObject) -() )

{

// Some work

 completionHandler(variable)
}

getDetails 

{

variable in

print(variable)

}

My question is what is the sequence of function calls for this execution to happen?

Sahil
  • 9,096
  • 3
  • 25
  • 29
  • 2
    I'm having a hard time deciphering what is real code, what is pseudo code and what is spelling/syntax errors. Please give a better code example. Try compiling some sample code similar to this in a playground and see the execution for yourself. You can also use breakpoints to see how things are executed. – keithbhunter May 03 '16 at 12:44
  • Not a issue I have myself understood the flow. Thanks Though – Sachindeep Singh May 04 '16 at 11:38

1 Answers1

0

So the answer is when a function (say A) which has function(say B) as a parameter is called, the called function (A) execution begins. As soon as the function in parameter(function B) is called the flow goes to the point where function (A) was called. Execution of that code begins and after the execution of it, the left over part of the function(A) is executed.

In the above example when getDetails is called, the execution for that function begins but when completionHandler is called the flow jumps to the { part of getDetails, only after this is finished it comes back and starts executing after the completionHanldler() is called.