Tutorial by Examples

A defer statement consists of a block of code, which will be executed when a function returns and should be used for cleanup. As Swift's guard statements encourage a style of early return, many possible paths for a return may exist. A defer statement provides cleanup code, which then does not need ...
When using a defer-statement, make sure the code remains readable and the execution order remains clear. For example, the following use of the defer-statement makes the execution order and the function of the code hard to comprehend. postfix func ++ (inout value: Int) -> Int { defer { value...

Page 1 of 1