Re: [swift-users] Defer with local variable's state

2016-08-11 Thread Sebastian Hagedorn via swift-users
My bad. After double-checking my code, I realized that some branches were dispatching their work, which of course breaks that model. Sorry, and thanks for clarification that this is how it should works. > On 11 Aug 2016, at 17:39, Joe Groff wrote: > >> >> On Aug 11, 2016, at 7:16 AM, Sebasti

Re: [swift-users] Defer with local variable's state

2016-08-11 Thread Joe Groff via swift-users
> On Aug 11, 2016, at 7:16 AM, Sebastian Hagedorn via swift-users > wrote: > > We often write code that returns early, but has to make sure a bit of code > (e.g., a completion handler) is always called whenever we return, which seems > like a great use case for defer. I started to write this:

[swift-users] Defer with local variable's state

2016-08-11 Thread Sebastian Hagedorn via swift-users
We often write code that returns early, but has to make sure a bit of code (e.g., a completion handler) is always called whenever we return, which seems like a great use case for defer. I started to write this: func execute(with completion: ((Bool) -> Void)?) { var success = false