Swift稳定排序? [英] Swift Stable Sort?

查看:128
本文介绍了Swift稳定排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此时(2015年3月28日):如果我想在swift中使用稳定排序,我必须使用 NSArray sortWithOptions 或在Swift中编写我自己的稳定排序,例如插入排序 ?我在 Apple Swift docs 中看到已排序不稳定。

At this time (March 28, 2015): If I want to use a stable sort in swift, I have to use NSArray and sortWithOptions or write my own stable sort in Swift such as an insertion sort? I see in the Apple Swift docs that sorted is not stable.

NSMutableArray中稳定排序的示例

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

我错过了除了使用Objective-C或编写自己的Swift之外我可以使用的另一个选项排序?

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

推荐答案

正如@Michael所说,人们可以编写一个调用objective-c函数的swift-wrapper

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

这篇关于Swift稳定排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆