[swift-users] Capturing difference with typealias

Jon Shier jon at jonshier.com
Fri Aug 19 16:46:23 CDT 2016


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