iOS Interview Questions (Swift) — Part 3

For previous parts follow the link Part1 & Part2.. All About Closure & All About Properties

Animesh Mishra
4 min readMay 6, 2018

1. What is closure, where can we use it ?

  • They are self contained chunks of code that can be passed around and used in your code.
  • Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages.
  • They are almost the same as functions but don’t necessarily have a name.
  • No need to declare the type of each parameter, if you do so you don’t need to state the return type of the closure.

Follow the link for all type syntax of closure.

2. What are escaping/ nonescaping closures?

@nonescaping closures: (default closure)

  • When you are passing a closure in function’s arguments, using it before the function’s body gets execute and returns the compiler back.
  • When the function ends, the passed closure goes out of scope and have no more existence in memory.

@escaping closures: .

  • When are passing the closure in function’s arguments, using it after the function’s body

--

--