When NOT to use a defer statement

suggest change

When using a defer statement, keep the code readable and the execution order clear. The following use makes both hard to follow. The ++ operator was removed in Swift 3, so it is declared here first.

postfix operator ++

postfix func ++ (value: inout 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