Search
 
SCRIPT & CODE EXAMPLE
 

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]
}
Comment

PREVIOUS NEXT
Code Example
Swift :: swiftui circle 
Swift :: add corner radius to uiview swift 
Swift :: how do i get a string from a float swift to 1 decimal swift 
Swift :: swift ways to setup constraints 
Swift :: access bank swift code 
Swift :: power number in swift 
Swift :: swift dispatch queue 
Swift :: create dictionary swift 
Swift :: and in swift4 
Swift :: sort array alphabetically swift 4 
Swift :: how do i have countdown timer in swift stackoverflow 
Swift :: navigationbar large title swift 
Swift :: swift date to string 
Swift :: hide scroll view indicators bar swiftui 
Swift :: swift simulatore condition 
Swift :: uilabel make bold 
Swift :: swift inheritance 
Swift :: socket io swift 
Swift :: reprobate 
Swift :: swift extension Array where type 
Swift :: polymorphism in swift 
Swift :: how to loop in swift 
Swift :: Modifying Value Types from Method Swift 
Swift :: declaration of array in swift by two methods. 
Swift :: swift function 
Swift :: Swift Equatable Protocol 
Swift :: swiftui calendar 
Swift :: helen joseph 
Swift :: how to declare populated dictionary in swift 
Swift :: swift computed property 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =