Class: NSMutableDictionary
- Inherits:
-
NSDictionary
- Object
- NSObject
- NSDictionary
- NSMutableDictionary
Overview
The NSMutableDictionary class declares the programmatic interface to objects that manage mutable associations of keys and values. It adds modification operations to the basic operations it inherits from NSDictionary. NSMutableDictionary is “toll-free bridged” with its Core Foundation counterpart, CFMutableDictionaryRef. See “Toll-Free Bridging” for more information.
Direct Known Subclasses
Class Method Summary (collapse)
-
+ dictionaryWithCapacity:
Creates and returns a mutable dictionary, initially giving it enough allocated memory to hold a given number of entries.
-
+ dictionaryWithSharedKeySet:
Creates a mutable dictionary which is optimized for dealing with a known set of keys.
Instance Method Summary (collapse)
-
- addEntriesFromDictionary:
Adds to the receiving dictionary the entries from another dictionary.
-
- initWithCapacity:
Initializes a newly allocated mutable dictionary, allocating enough memory to hold numItems entries.
-
- removeAllObjects
Empties the dictionary of its entries.
-
- removeObjectForKey:
Removes a given key and its associated value from the dictionary.
-
- removeObjectsForKeys:
Removes from the dictionary entries specified by elements in a given array.
-
- setDictionary:
Sets the contents of the receiving dictionary to entries in a given dictionary.
-
- setObject:forKey:
Adds a given key-value pair to the dictionary.
-
- setObject:forKeyedSubscript:
Adds a given key-value pair to the dictionary.
-
- setValue:forKey:
Adds a given key-value pair to the dictionary.
Methods inherited from NSDictionary
#allKeys, #allKeysForObject:, #allValues, #count, #description, #descriptionInStringsFileFormat, #descriptionWithLocale:, #descriptionWithLocale:indent:, dictionary, dictionaryWithContentsOfFile:, dictionaryWithContentsOfURL:, dictionaryWithDictionary:, dictionaryWithObject:forKey:, dictionaryWithObjects:forKeys:, dictionaryWithObjects:forKeys:count:, dictionaryWithObjectsAndKeys:, #enumerateKeysAndObjectsUsingBlock:, #enumerateKeysAndObjectsWithOptions:usingBlock:, #fileCreationDate, #fileExtensionHidden, #fileGroupOwnerAccountID, #fileGroupOwnerAccountName, #fileHFSCreatorCode, #fileHFSTypeCode, #fileIsAppendOnly, #fileIsImmutable, #fileModificationDate, #fileOwnerAccountID, #fileOwnerAccountName, #filePosixPermissions, #fileSize, #fileSystemFileNumber, #fileSystemNumber, #fileType, #getObjects:andKeys:, #initWithContentsOfFile:, #initWithContentsOfURL:, #initWithDictionary:, #initWithDictionary:copyItems:, #initWithObjects:forKeys:, #initWithObjects:forKeys:count:, #initWithObjectsAndKeys:, #isEqualToDictionary:, #keyEnumerator, #keysOfEntriesPassingTest:, #keysOfEntriesWithOptions:passingTest:, #keysSortedByValueUsingComparator:, #keysSortedByValueUsingSelector:, #keysSortedByValueWithOptions:usingComparator:, #objectEnumerator, #objectForKey:, #objectForKeyedSubscript:, #objectsForKeys:notFoundMarker:, sharedKeySetForKeys:, #valueForKey:, #writeToFile:atomically:, #writeToURL:atomically:
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) dictionaryWithCapacity(numItems)
Creates and returns a mutable dictionary, initially giving it enough allocated memory to hold a given number of entries. Mutable dictionaries allocate additional memory as needed, so numItems simply establishes the object’s initial capacity.
+ (Object) dictionaryWithSharedKeySet(keyset)
Creates a mutable dictionary which is optimized for dealing with a known set of keys. Keys that are not in the key set can still be set in the dictionary, but that usage is not optimal.
Instance Method Details
- (Object) addEntriesFromDictionary(otherDictionary)
Adds to the receiving dictionary the entries from another dictionary. Each value object from otherDictionary is sent a retain message before being added to the receiving dictionary. In contrast, each key object is copied (using copyWithZone:—keys must conform to the NSCopying protocol), and the copy is added to the receiving dictionary.If both dictionaries contain the same key, the receiving dictionary’s previous value object for that key is sent a release message, and the new value object takes its place.
- (Object) initWithCapacity(numItems)
Initializes a newly allocated mutable dictionary, allocating enough memory to hold numItems entries. Mutable dictionaries allocate additional memory as needed, so numItems simply establishes the object’s initial capacity.
- (Object) removeAllObjects
Empties the dictionary of its entries. Each key and corresponding value object is sent a release message.
- (Object) removeObjectForKey(aKey)
Removes a given key and its associated value from the dictionary. Does nothing if aKey does not exist.For example, assume you have an archived dictionary that records the call letters and associated frequencies of radio stations. To remove an entry for a defunct station, you could write code similar to the following:Important: Raises an NSInvalidArgumentException if aKey is nil.
- (Object) removeObjectsForKeys(keyArray)
Removes from the dictionary entries specified by elements in a given array. If a key in keyArray does not exist, the entry is ignored.
- (Object) setDictionary(otherDictionary)
Sets the contents of the receiving dictionary to entries in a given dictionary. All entries are removed from the receiving dictionary (with removeAllObjects), then each entry from otherDictionary added into the receiving dictionary.
- (Object) setObject(anObject, forKey:aKey)
Adds a given key-value pair to the dictionary.
- (Object) setObject(object, forKeyedSubscript:aKey)
Adds a given key-value pair to the dictionary. This method is identical to setObject:forKey:.
- (Object) setValue(value, forKey:key)
Adds a given key-value pair to the dictionary. This method adds value and key to the dictionary using setObject:forKey:, unless value is nil in which case the method instead attempts to remove key using removeObjectForKey:.