A mutable, unordered collection of distinct objects that may appear more than once in the collection.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Each distinct object inserted into an
NSCounted object has a counter associated with it.
NSCounted keeps track of the number of times objects are inserted and requires that objects be removed the same number of times. Thus, there is only one instance of an object in an
NSSet object even if the object has been added to the set multiple times. The
count method defined by the superclass
NSSet has special significance; it returns the number of distinct objects, not the total number of times objects are represented in the set. The
NSMutable classes are provided for static and dynamic sets, respectively, whose elements are distinct.
CFBag are not toll-free bridged, they provide similar functionality. For more information about
CFBag, see the CFBag.
NSCounted is not a class cluster, it does not have primitive methods that provide the basis for its implementation. In general, there should be little need for subclassing.
Methods to Override
If you subclass
NSCounted, you must override any method of which you want to change the behavior.
If you change the primitive behavior of an
NSCounted, for instance if you change how objects are stored, you must override all of the affected methods. These include:
If you change the primitive behavior, you must also override the primitive methods of