> On Jan 2, 2016, at 9:38 AM, Nicky Gerritsen <[email protected]> wrote:
>
> Defer is used to make code *always* run, even if the function terminates
> early. Imagine:
Which is precisely why I called it 'always'. So in your example:
func doSomethingWith(x: Int) {
print(“1”)
defer { print(“2") }
if x > 3 { defer { print(“yay”); return }
print(“3”)
}
I would say:
func doSomethingWith(x: Int) {
print(“1”)
print(“3”)
always {
print(“2")
if x > 3 { print(“yay”) }
}
}
This is functionally identical, but both the syntax and program flow are
greatly improved.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution