Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

swift remove all duplicates from an array

extension Sequence where Element: Hashable {
    func uniqued() -> [Element] {
        var set = Set<Element>()
        return filter { set.insert($0).inserted }
    }
}

func foobar() {
    let myUniqueArray = [1,2,4,2,1].uniqued()  // => [1,2,4]
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #swift #remove #duplicates #array
ADD COMMENT
Topic
Name
9+5 =