Answers for "how to remove repeatable entries from array of struct in swift"

0

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]
}
Posted by: Guest on June-18-2021

Code answers related to "how to remove repeatable entries from array of struct in swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language