When NOT to use a defer statement
suggest changeWhen 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
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents