1

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.

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.