Swift 3 introduces the CountedSet
class (it's the Swift version of the NSCountedSet
Objective-C class).
CountedSet, as suggested by the name, keeps track of how many times a value is present.
let countedSet = CountedSet()
countedSet.add(1)
countedSet.add(1)
countedSet.add(1)
countedSet.add(2)
countedSet.count(for: 1) // 3
countedSet.count(for: 2) // 1