swift 数组中去除重复的办法
不确保顺序
var array = [1, 2, 3, 4, 5, 55, 89, 20, 20, 1, 2, 3]
if Set(array).count != array.count {
array = Array(Set(array))
}
print(array)
// [89, 2, 55, 4, 20, 5, 3, 1]
重新排序
array = array.sort( < )
print(array)
// [1, 2, 3, 4, 5, 20, 55, 89]
网友评论