我使用它对Swift中的数组中的组件进行排序:
myArray = myArray.sorted { $0.localizedCaseInsensitiveCompare($1) == NSComparisonResult.OrderedAscending }然而,它给了我以下结果:
[18C, 18L, 18R, 22, 24, 27, 36C, 36L, 36R, 4, 6, 9]能不能把它按正确的方式分类呢?
[4, 6, 9, 18C, 18L, 18R, 22, 24, 27, 36C, 36L, 36R]发布于 2014-11-16 05:27:07
您可以将compare与.NumericSearch结合使用
array.sortInPlace { $0.compare($1, options: .NumericSearch) == .OrderedAscending }或
let array2 = array.sort { $0.compare($1, options: .NumericSearch) == .OrderedAscending }https://stackoverflow.com/questions/26954029
复制相似问题