Beginner Swift
Q16 / 100

What does the defer statement do?

Correct! Well done.

Incorrect.

The correct answer is B) Executes code when the current scope exits, regardless of how it exits

B

Correct Answer

Executes code when the current scope exits, regardless of how it exits

Explanation

defer { cleanup() } ensures cleanup() runs when the function exits — even via return, throw, or error. Useful for resource cleanup.

Progress
16/100