Quick "ambiguous use of the"> "operator
I just downloaded Xcode6-beta6. I am getting compiler error "ambiguous use of operator"> "for the following codes
reversed = sorted(names, { s1, s2 in s1 > s2 } )
It worked before in Xcode6-beta5.
Code from Apple swift documentation https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-XID_152
Any ideas?
source to share
I had the same problem with
if ("aa" > "bb") {
[...]
}
and
reverseed = sorted (names, {$ 0> $ 1})
Apparently, Xcode cannot correctly infer the correct "String" type for parameters, thus creating operator ambiguity. My solution was to explicitly declare the type of at least one of them, which also makes the code more readable. How in:
if ("aa" as String > "bb") { [...] }
reverseed = sorted (names, {$ 0 as String> $ 1})
source to share
This looks like a bug in the Foundation framework bridges. It declares overrides >
to handle comparisons String
with NSString
and NSString
and a String
, but they appear (in some cases) in conflict with the match. You can get around this (for some reason) by changing your syntax a bit:
reversed = sorted(names, { s1, s2 in return s1 > s2 } )
source to share