我想知道如何用Swift 3中的另一个数组对数组进行排序
让我说我有:
[channel3, channel2, channel1, channel4, channel5]
我希望将原始数组排序为:
function compare($p){
return $p == $z;
}
有没有快速,低耗的方式来做到这一点?
答案 0 :(得分:1)
favorites.append(contentsOf: original.filter { chanel in
!favorites.contains(where: { $0.id == chanel.id })
})
答案 1 :(得分:0)
Zip是实现此目的的简便方法
// use zip to combine the two arrays and sort that based on the first
// Your original array
let combined = zip(array1, array2).sort {$0.0 < $1.0}
print(combined) //
// Now use map to extract the individual arrays
let sorted1 = combined.map {$0.0}
let sorted2 = combined.map {$0.1}
希望有所帮助