#import <Foundation/Foundation.h>
Instance Methods | |
(unsigned int) | - count |
Returns the number of elements in the map. More... | |
(size_t) | - capacity |
Returns the capacity of the map. More... | |
(NXArray *) | - allKeys |
Returns an array containing all keys stored in the map. More... | |
(NXArray *) | - allObjects |
Returns an array containing all objects stored in the map. More... | |
(BOOL) | - setObject:forKey: |
Stores an object in the map with the specified key. More... | |
(id) | - objectForKey: |
Retrieves an object from the map by its key. More... | |
(BOOL) | - removeObjectForKey: |
Removes an object from the map by its key. More... | |
(void) | - removeAllObjects |
Removes all objects from the map. More... | |
![]() | |
(id) | - retain |
Increases the retain count of the receiver. More... | |
(void) | - release |
Decreases the retain count of the receiver. More... | |
(id) | - autorelease |
Adds the receiver to the autorelease pool. | |
![]() | |
(void) | - dealloc |
Free resources for an existing instance. | |
(id) | - init |
Initialize the instance, after allocation. More... | |
(Class) | - class |
Returns the class of the instance. More... | |
(Class) | - superclass |
Returns the superclass of the instance. More... | |
(BOOL) | - isEqual: |
Compares the receiver to another object for equality. More... | |
(BOOL) | - isKindOfClass: |
Returns a Boolean value that indicates whether the receiver is an instance of a given class. More... | |
(BOOL) | - conformsTo: |
Checks if the receiver's class conforms to a protocol. More... | |
(NXString *) | - description |
Returns a string that represents the instance. More... | |
![]() | |
(BOOL) | - respondsToSelector: |
Checks if the receiver responds to a selector. More... | |
![]() | |
(NXString *) | - JSONString |
Returns a JSON representation of the instance. More... | |
(size_t) | - JSONBytes |
Returns the appropriate capacity for the JSON representation of the instance. More... | |
![]() | |
(BOOL) | - containsObject: |
Returns YES if the collection contains the specified object. More... | |
Class Methods | |
(NXMap *) | + new |
Returns a new empty NXMap instance. | |
(NXMap *) | + mapWithCapacity: |
Returns a new NXMap instance with the specified initial capacity. More... | |
(NXMap *) | + mapWithObjectsAndKeys: |
Creates and returns a new NXMap initialized with alternating objects and keys. More... | |
(NXMap *) | + mapWithObjects:forKeys: |
Creates and returns a new NXMap initialized with objects from one array and corresponding keys from another array. More... | |
![]() | |
(id) | + allocWithZone: |
Allocates a new instance of an object in a specific memory zone. More... | |
![]() | |
(void) | + initialize |
Performs one-time initialization for the class. More... | |
(id) | + alloc |
Allocate a new class instance. More... | |
(Class) | + class |
Returns the class object. More... | |
(Class) | + superclass |
Returns the superclass of the class. More... | |
(const char *) | + name |
Returns the name of the class. More... | |
(BOOL) | + conformsTo: |
Checks if the class conforms to a protocol. More... | |
(NXString *) | + description |
Returns a string that represents the class. More... | |
Additional Inherited Members | |
![]() | |
id | _zone |
The memory zone where the object is allocated. | |
unsigned short | _retain |
The retain count of the object. | |
id | _next |
The next object in an autorelease pool. | |
![]() | |
Class | isa |
A pointer to the object's class structure. More... | |
The NXMap class.
NXMap represents a map that can store key-value pairs, where keys are strings and values are arbitrary objects.
The map uses an optimized hash table implementation for efficient storage and retrieval of key-value pairs. Keys must be string objects that implement the NXConstantStringProtocol.
Objects stored in the map are retained and will be released when the map is deallocated, when an object is removed, or when removeAllObjects is called.
- (NXArray *) allKeys |
Returns an array containing all keys stored in the map.
The order of keys in the returned array is not guaranteed to match the order of insertion. The array contains only the keys stored in the map, not the associated objects.
- (NXArray *) allObjects |
Returns an array containing all objects stored in the map.
The order of objects in the returned array is not guaranteed to match the order of insertion. The array contains only the values stored in the map, not the keys.
- (size_t) capacity |
Returns the capacity of the map.
- (unsigned int) count |
Returns the number of elements in the map.
Reimplemented from <CollectionProtocol>.
+ (NXMap *) mapWithCapacity: | (size_t) | capacity |
Creates and returns a new NXMap initialized with objects from one array and corresponding keys from another array.
objects | An NXArray containing the objects to store in the map. Must not be nil and must contain the same number of elements as keys. |
keys | An NXArray containing the keys to associate with the objects. Must not be nil, must contain the same number of elements as objects, and all elements must implement the NXConstantStringProtocol. |
This method creates a new map by pairing elements at corresponding indices from the two input arrays. The first element of the objects array is paired with the first element of the keys array, the second with the second, and so on.
Example usage:
Both arrays must contain the same number of elements. If they differ in size, the behavior is undefined.
Creates and returns a new NXMap initialized with alternating objects and keys.
firstObject | The first object to store in the map, followed by its key, then the next object, its key, and so on. The list must be terminated with nil. |
... | A nil-terminated list of alternating objects and keys. |
This method creates a new map by taking pairs of arguments where each odd argument is an object and each even argument is its corresponding key. The argument list must be terminated with nil. Keys must implement the NXConstantStringProtocol.
Example usage:
- (id) objectForKey: | (id< NXConstantStringProtocol, RetainProtocol >) | key |
Retrieves an object from the map by its key.
key | The string key to look up. Must be non-nil and implement both the NXConstantStringProtocol and RetainProtocol. |
- (void) removeAllObjects |
Removes all objects from the map.
This method effectively clears all key-value pairs from the map. All previously stored objects are released, and any references to them become invalid. The map remains fully functional after this operation and can accept new key-value pairs immediately.
- (BOOL) removeObjectForKey: | (id< NXConstantStringProtocol, RetainProtocol >) | key |
Removes an object from the map by its key.
key | The string key of the object to remove. Must be non-nil and implement both the NXConstantStringProtocol and RetainProtocol. |
When an object is successfully removed, it is released by the map. The map's count is decremented by one. If the key is not found, the map remains unchanged.
- (BOOL) setObject: | (id) | anObject | |
forKey: | (id< NXConstantStringProtocol, RetainProtocol >) | key | |
Stores an object in the map with the specified key.
anObject | The object to store in the map. Must be non-nil. |
key | The string key to associate with the object. Must be non-nil and implement both the NXConstantStringProtocol and RetainProtocol. |
If a key already exists in the map, the new object will overwrite the existing one. The object is retained by the map.