finneycanhelp finneycanhelp - 1 year ago 73
Swift Question

Swift Stable Sort?

At this time (March 28, 2015): If I want to use a stable sort in swift, I have to use

or write my own stable sort in Swift such as an insertion sort? I see in the Apple Swift docs that
is not stable.

Example of stable sort in NSMutableArray:

[array sortWithOptions:NSSortStable usingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2];

Am I missing another option that's available to me in Swift other than using Objective-C or writing my own sort?

Answer Source

As @Michael put it, one can "write a swift-wrapper that calls the objective-c function"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download