I have a method that can be summed up to look like this:
func apply(username: String, email: String, password: String,
onDone: @escaping (_ error: Error?) -> ())
{
//Do async stuff
do
{
try asyncGood()
onDone(nil)
return
}
catch
{
onDone(error)
return
}
}
What's the difference between doing:
return onDone(error)
versus
onDone(error)
return
?
Does it just save an extra line of code? I don't see any difference between the two. Am I missing some fundamental aspect of asynchronous Swift programming?
In your opinion, should I always try to condense everything down such that onDone(...) only gets called once at the end?
onDone(...), I've found that it gets called multiple times which calls subsequent code multiple times. So, that's why I always terminate myonDone(...)s with return statements out of habit. - Xavier L.