1

This code was compiling on Xcode 8 beta 5 but broken in beta 6. What is the right new Swift 3 way to do this comparison?

self.categories = categories.sorted { $0.localizedCaseInsensitiveCompare($1) == ComparisonResult.orderedDescending }

The error is

Argument passes to call that takes no arguments

Jason Hocker
  • 6,879
  • 9
  • 46
  • 79

2 Answers2

1

I just have succeeded to get the same error message.

In my testing code, if I declare the instance property categories as:

var categories: [NSString] = []

I have got this error message:

error: argument passed to call that takes no arguments

If your case is very similar to this, you need to change the property declaration to:

var categories: [String] = []

Even if this does not fit for your issue, you'd better check this sort of type-mismatching, because as of Swift 3/Xcode 8 beta 6:

  • Bridging conversions are no longer implicit. The conversion from a Swift value type to its corresponding object can be forced with as. For example: string as NSString. Any Swift value can also be converted to its boxed id representation with as AnyObject. (SE-0072)

(Taken from the Release Notes of Xcode 8 beta 6.)

OOPer
  • 47,149
  • 6
  • 107
  • 142
  • The problem is self.categories was an NSArray?. I thought the issue was with the sort command because it discussed arguments. – Jason Hocker Aug 23 '16 at 18:11
  • @JasonHocker, Swift 3 is evolving so swift that Swift team have no time to refine its diagnostic messages. When Swift cannot find a matching overload of `sorted` which returns an expected type (in your case `NSArray`?), it sometimes output this sort of inadequate and confusing message. And I think this sort of bad diagnostics should be considered as bug, and you'd better send a bug report to Apple or swift.org. – OOPer Aug 23 '16 at 22:18
1

Same issue here. I tried to compile a snippet from the official Swift 3 guide in Xcode beta and got the same error - Argument passes to call that takes no arguments. Though, when I used IBM Swift Sandbox, it compiled successfully.

let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]
func backward(_ s1: String, _ s2: String) -> Bool {
return s1 > s2
}
var reversedNames = names.sorted(by: backward)

From looking here, it seems that the API of sorted changed from x.sorted(isOrderedBefore: >) to x.sorted(by: >). I guess that in the future Xcode beta, this will be taken care of.

bentz123
  • 1,081
  • 7
  • 16
  • another way of writing that: var reversedNames = names.sorted(by: {s1, s2 -> Bool in s1 > s2 }) – Edudjr Apr 06 '17 at 15:20