But if the closure can escape it is difficult to guarantee that it is executed at all (e.g. in your examples such as dispatch_async).
-Thorsten
···
Am 29. Januar 2016 um 11:58 schrieb Brent Royal-Gordon via swift-evolution swift-evolution@swift.org:
You are right Jacob, a modifier @noescape(once) would be better, as it would help compiler distinguish between assignment and initialization of captured variables.
The utility of such a new feature is maybe tiny, but clear: it extends the opportunities to declare variables before initializing them. The Swift 1 to 2 transition has already extended those opportunities, so we’re just following an existing trend, here.
I actually think that once is orthogonal to noescape. There are a lot of closures that are not noescape, but are called exactly once, such as dispatch_async and most completion handlers.
let x: Int // Not initialized
f { x = 1 }
print(x) // Guaranteed to be initialized
Such closure can not escape. Hence @noescape(once), not @once.
dispatch_sync() is often cited in this mailing list, and we all want that it declares its argument as @noescape. Now it would be even better if it would declare it as @noescape(once).
Gwendal
···
Le 29 janv. 2016 à 13:11, Thorsten Seitz <tseitz42@icloud.com> a écrit :
But if the closure can escape it is difficult to guarantee that it is executed at all (e.g. in your examples such as dispatch_async).
-Thorsten
Am 29. Januar 2016 um 11:58 schrieb Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org>:
You are right Jacob, a modifier `@noescape(once)` would be better, as it would help compiler distinguish between assignment and initialization of captured variables.
The utility of such a new feature is maybe tiny, but clear: it extends the opportunities to declare variables before initializing them. The Swift 1 to 2 transition has already extended those opportunities, so we’re just following an existing trend, here.
I actually think that `once` is orthogonal to `noescape`. There are a *lot* of closures that are not noescape, but are called exactly once, such as dispatch_async and most completion handlers.