defer
keyword in Swift?Suggested approach: Go straight in with a clear explanation before adding more detail: this is used to delay a piece of work until a function ends, similar to how try
/finally
works in some other languages.
Once you've done that, be sure to give a specific example such as saving a file once everything has been written – any kind of work that absolutely must take place.
For bonus points, mention how you can defer multiple pieces of work, and they get executed in reverse as Swift unwinds the defer
stack.
Estimated difficulty: Intermediate
See the full list of iOS interview questions
Link copied to your pasteboard.