我遇到错误
闭包中不包含匿名闭包参数
我有一个如下所示的数组,我想删除重复的元素以获得没有任何重复的新数组,我的swift代码是:-
let oldArray = [1,2,3,4,5,6,7,8,91,2,3,6]
var newArray = oldArray.map( $0 != $1)
print(newArray)
预先感谢
答案 0 :(得分:0)
您可以尝试
let newArray = Array(Set(oldArray))
OR
let oldArray = [1,2,3,4,5,6,7,8,91,2,3,6]
var newArray = [Int]()
oldArray.forEach {
if !newArray.contains($0) {
newArray.append($0)
}
}
print(newArray)