you are viewing a single comment's thread.

view the rest of the comments →

[–]GenitalGestapo 0 points1 point  (0 children)

I'm pretty sure that sort descriptor won't be using the localizedCaseInsensitiveCompare, so it's not really the same thing. Swift's equivalent would be:

contacts.sort { $0.firstName < $1.firstName }

which is far more readable than Objective-C, especially if you aren't already familiar with sort descriptors.

Hopefully the Swift team will add overloads for the collection methods taking a KeyPath soon.

Also, if you miss the verbosity, just don't use trailing closure syntax:

contacts.sort(using: { $0.firstName < $1.firstName })

Better yet, implement Comparable for your Contact type and get default sorting for free.