> Le 23 avr. 2016 à 15:47, [email protected] a écrit :
>
> why not just write
>
> func f(closure: @once () -> ()) // ?
>
> Because, to be honest, I don't want to have to learn the difference between
> an "argument qualifier" and a "type attribute".
I'm with you here, but I will certainly not fight a Swift lawyer about the
actual syntax :-)
For me the best syntax is the following because it makes the @noescape
explicit, so that I know that I don't need to use explicit `self.` inside the
closure.
func f(closure: @noescape(once) () -> ())
let x: Int
f { x = myIntProperty } // implicit self
> When I think of it, my experimental synchronized-function would also profit
> from '@once':
>
> /// same as Objective-C's @synchronized(object) { ... } function.
> func synchronized<T>(lock: AnyObject, @noescape _ closure: () throws -> T)
> rethrows -> T {
> var result: T;
> objc_sync_enter(lock)
> defer { objc_sync_exit(lock) }
> result = try closure()
> return result;
> }
I'm glad you see the point :-) I really believe that @noescape(once) is on the
same boat as SE-0061 "Add Generic Result and Error Handling to
autoreleasepool()
https://github.com/apple/swift-evolution/blob/master/proposals/0061-autoreleasepool-signature.md
Gwendal
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution