NSMap class is a mutable collection modeled after
NSDictionary, with the following differences:
- iOS 6.0+
- macOS 10.5+
- tvOS 9.0+
- watchOS 2.0+
The major option is to have keys and/or values held “weakly” in a manner that entries are removed when one of the objects is reclaimed.
Its keys or values may be copied on input or may use pointer identity for equality and hashing.
It can contain arbitrary pointers (its contents are not constrained to being objects).
You can configure an
NSMapinstance to operate on arbitrary pointers and not just objects, although typically you are encouraged to use the C function API for
void *pointers. (See Managing Map Tables for more information) The object-based API (such as
set) will not work for non-object pointers without type-casting.
Object(_: for Key:)
When configuring map tables, note that only the options listed in
NSMap guarantee that the rest of the API will work correctly—including copying, archiving, and fast enumeration. While other
NSPointer options are used for certain configurations, such as to hold arbitrary pointers, not all combinations of the options are valid. With some combinations the map table may not work correctly, or may not even be initialized correctly.
NSMap is not suitable for subclassing.