When NOT to use a defer statement

suggest change

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 += 1 } // do NOT do this!
    return value
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents