[swift-users] Capturing difference with typealias

Jon Shier jon at jonshier.com
Fri Aug 19 19:27:18 CDT 2016


Another general question I have is how the self requirement in general has changed. I’m noticing several instances where my previous @noescape closures, which of course had that attribute removed, are now requiring self when they didn’t before and aren’t marked @escaping either. So I guess my question is, should there ever be an instance where a closure not marked @escaping requires the use of self?


Jon

> On Aug 19, 2016, at 5:46 PM, Jon Shier <jon at jonshier.com> wrote:
> 
> Users:
> 	I’m updating more code to beta 6 and have noticed a strange difference when calling functions with closure parameters where that closure is declared with a typealias. Take this class:
> 
> typealias Closure = () -> Void
> 
> class Thing {
>    var array: [String] = []
> 
>    func doClosure(closure: Closure) {
>        array.append("closure")
>    }
> 
>    func doManualClosure(manualClosure: () -> Void) {
>        array.append("manualClosure")
>    }
> 
>    func append() {
>        doClosure {
>            doClosure {
> 
>            }
>        }
>    }
> 
>    func appendManual() {
>        doManualClosure {
>            doManualClosure {
> 
>            }
>        }
>    }
> }
> 
> There’s an error triggered by the doClosure call inside a doClosure call saying that I need an explicit self capture. However, the same pattern in appendManual() builds just fine. I’m guessing this is a bug?
> 
> 
> 
> Jon



More information about the swift-users mailing list