Swift Language Sets CountedSet

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

3.0

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


Got any Swift Language Question?