Removing duplicate elements from an array in Swift

后端 未结 30 2523
遥遥无期
遥遥无期 2020-11-22 00:07

I might have an array that looks like the following:

[1, 4, 2, 2, 6, 24, 15, 2, 60, 15, 6]

Or, reall

30条回答
  •  孤街浪徒
    2020-11-22 00:36

    You can convert to a Set and back to an Array again quite easily:

    let unique = Array(Set(originals))
    

    This is not guaranteed to maintain the original order of the array.

提交回复
热议问题