所以我有2个阵列
let knownOrder = ["Headache level", "Headache side", "Nausea", "Aura", "Phonophobia" ,"Photophobia"]
let tmpArray = ["Aura","Headache side","Photophobia"]
现在我要做的是对“tmpArray”进行排序。按照“已知订单”的顺序排列。
我该怎么办?
答案 0 :(得分:4)
过滤knownOrder
以删除tmpArray
中没有的任何元素:
let knownOrder = ["Headache level", "Headache side", "Nausea", "Aura", "Phonophobia" ,"Photophobia"]
let tmpArray = ["Aura","Headache side","Photophobia"]
let ordered = knownOrder.filter { tmpArray.contains($0) }
print(ordered)
["头痛方面","灵气","畏光"]