How can we create unique object list in Swift language like NSSet & NSMutableSet in Objective-C.
You actually can create a Set object pretty easy (in contradiction to GoZoner, there is a built in contains method):
class Set {
var items : T[] = []
func add(item : T) {
if !contains(items, {$0 == item}) {
items += item
}
}
}
and you maybe even want to declare a custom operator:
@assignment @infix func += (inout set : Set, items : T[]) -> Set {
for item in items {
set.add(item)
}
return set
}