Swift稳定排序? [英] Swift Stable Sort?
本文介绍了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.
[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屋!
查看全文