1.

Predict the output of the ios Swift code snippet given below

Answer»

var item = "apples"let closure = { print("He WANTED to EAT \(item)")}item = "oranges"closure()

The above-given code SNIPPET PRINTS "He wanted to eat oranges". If you do not include a capture list in the closure, the compiler will use a reference rather than a copy. As a result, any change to the variable is REFLECTED when the closure is invoked. 



Discussion

No Comment Found