gooberboobbutt gooberboobbutt - 6 months ago 10
Swift Question

If you have "return" in brackets, will following code outside of the bracket not be executed?

Here is the code in question.

if let error = error {
print(error.localizedDescription)
return
}

self.userSetDisplayName(user!)


So if error != nil and it lets error = error, it will print to the console and return, so it will not run userSetDisplayName. Otherwise if error == nil, it doesnt print and it does not return and it will run userSetDisplayName. Is this the case?

Answer

Yes. Any return statement will end the current subprogram.

Also: This is not a bracket: {, it's a curly brace, or just braces