NSHashTable & NSMapTable

NSSet and NSDictionary, along with NSArray are the workhorse collection classes of Foundation. Unlike other standard libraries, implementation details are hidden from developers, allowing them to write simple code and trust that it will be (reasonably) performant.

nshipster.com/nshashtable-and-nsmaptable/

NSHashTable acts as a general version of NSSet. It is mutable, holds weak references, can copy items on input, and handles arbitrary pointers using pointer identity for equality and hashing.

NSMapTable serves as a general version of NSDictionary. It is mutable, supports weak references for keys and values (removing entries if either deallocates), can copy values on input, and works with arbitrary pointers.

Use these when standard collections' strong references or copying rules do not fit, such as for weak delegates or non-copyable keys. For most cases, NSSet and NSDictionary suffice.


Category:

Year: