[swift-evolution] Closure delegation

James Campbell james at supmenow.com
Fri Dec 11 04:54:46 CST 2015


Could you explain a little more its a bit confusing ?

On Fri, Dec 11, 2015 at 10:32 AM, Pierre Monod-Broca via swift-evolution <
swift-evolution at swift.org> wrote:

> A groovy closure can have a delegate which replaces `this` as the default
> receiver. The issue in groovy is that it is not compatible with static
> compilation, and there is no way to know from the code what is the type of
> the delegate.
>
> It works great for DSL. It would work great the Swift Package Manager
> manifest, among other things.
>
> It could look like this in swift
>
> protocol Bar {
>     var someConfig: String { get set }
> }
>
> func prepareSomething(setup: @delegate Bar -> () -> ()) {
>     let bar = BarImplementation()
>     // code before
>     setup(bar)()
>     // code after
> }
>
> prepareSomething { () -> () in
>     someConfig = "Hello world"
> }
>
> Where `someConfig` would refer to bar.
>
> Pierre
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>


-- 
 Wizard
james at supmenow.com
+44 7523 279 698
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151211/d7020173/attachment.html>


More information about the swift-evolution mailing list