I am getting a compile time error that myFunc reference is ambiguous.
func f (s: String) -> String { return "version 1: " + s }
func f(sourceString s: String) -> String { return "version 2: " + s }
var myFunc: (String)-> String = f as (sourceString : String)->String
How can I explicitly reference each version of the overloaded function, f, in the example above? If I comment out either declaration of func f
it will compile and work. But I would like to know how to reference each of the functions if both are declared. Thanks.
Referencing
func f (s: String) -> String { return "version 1: " + s }
:Referencing
func f(sourceString s: String) -> String { return "version 2: " + s }
:Referencing
func anotherFunction(_ param: Any) {}
:If you haven't overloaded the function, you don't need to explicity write out the parameter names when referencing the function.
I don't know how to do exactly what you want, but maybe this helps:
You can now call:
Interesting one this. I don’t think it’s possible without doing something along the lines of @marcos’s suggestion. The problem you is you can “cast away” the names in tuples:
Now suppose you define two functions, identical except one has named arguments:
You can then call it via tuples with named vs unnamed arguments:
But because you can cast away these names you can do this:
And this ability to do this means it’s not possible to use a type to disambiguate an function overloaded only by argument names, as far as I can tell.
Example
I don't think you can. You can call one or the other: