You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when I read ´outside of the scope that the defer statement appears in.´ I assume that scope is above and below of ´defer´ statement. But this is wrong. defer will work only at half of scope, which is below ´defer´ statement.
below code will execute ´defer´ right after of guard body's ´return´ statement
func someFunction() {
defer {
print("defer works")
}
guard false else {
print("inside guard")
return
}
print("bottom of function")
}
// prints
// inside guard
// defer works
but if we put ´defer´ after guard statement, then ´defer´will not be invoked:
Location
Description
when I read ´outside of the scope that the defer statement appears in.´ I assume that scope is above and below of ´defer´ statement. But this is wrong. defer will work only at half of scope, which is below ´defer´ statement.
below code will execute ´defer´ right after of guard body's ´return´ statement
but if we put ´defer´ after guard statement, then ´defer´will not be invoked:
Correction
Maybe you should document ´defer´ like as ~ ´right after defer statement appears in´
The text was updated successfully, but these errors were encountered: