Reputation: 109
Since I upgraded to Swift 1.2, I have this weird problem, that I cannot resolve. Here is the code that causes all the trouble:
internal class Test<T,U> {
internal class func closureFunc(#arg: T, worker: (first: T, second: String) -> U, closure: ((u: U) -> Void)?) -> Void {
println("Something")
}
}
Test.closureFunc(arg: "", worker: { (first, second) -> Void in
//code
}) { (u) -> Void in
//code
}
The error itself says:
"Function signature (Void) -> Void is not compatible with expected type (u: Void) -> Void".
I read all about Swift 1.2 and I still can't seem to find a reasonable explanation for this. I will be extremely thankful for any tips and suggestions.
PS: I just saw this topic, that is similar to mine but removing the parameter name in the closure didn't quite work for me.
Upvotes: 1
Views: 147
Reputation: 13283
This seems to be a bug in Swift 1.2 (and even Swift 2 (Xcode 7 beta 3)) with single parameter closures with external names.
As workaround you can remove the external parameter name "u":
internal class func closureFunc(#arg: T, worker: (first: T, second: String) -> U, closure: (U -> Void)?) -> Void
in Swift 2 (only) there is another workaround where you can give the passed closure an external name (since this would conform to the new and more strict naming conventions):
Test.closureFunc(arg: "", worker: { (first, second) -> Void in
//code
}) { (anyExternalNameWorks u: Void) -> Void in
//code
}
Upvotes: 1