How can we create unique object list in Swift language like NSSet & NSMutableSet in Objective-C.
I wrote a function to solve this problem.
public func removeDuplicates(aCollection: C) -> C {
var container = C()
for element in aCollection {
if !contains(container, element) {
container.append(element)
}
}
return container
}
To use it, just pass an array which contains duplicate elements to this function. And then it will return a uniqueness-guaranteed array.
You also can pass a Dictionary, String or anything conforms to ExtensibleCollectionType protocol if you like.