Class: NSMutableDictionary

Inherits:
NSDictionary show all

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

Hash

Class Method Summary (collapse)

Instance Method Summary (collapse)

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.

Parameters:

  • numItems (Integer)

    The initial capacity of the new dictionary.

Returns:

  • (Object)

    A new mutable dictionary with enough allocated memory to hold numItems entries.

+ (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.

Parameters:

  • keyset (Object)

    The keyset, created by the NSDictionary class method sharedKeySetForKeys:. If keyset is nil, an exception is thrown. If keyset is not an object returned by sharedKeySetForKeys:, an exception is thrown.

Returns:

  • (Object)

    A new mutable dictionary optimized for a known set of keys.

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.

Parameters:

  • otherDictionary (Hash)

    The dictionary from which to add entries

Returns:

- (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.

Parameters:

  • numItems (Integer)

    The initial capacity of the initialized dictionary.

Returns:

  • (Object)

    An initialized mutable dictionary, which might be different than the original receiver.

- (Object) removeAllObjects

Empties the dictionary of its entries. Each key and corresponding value object is sent a release message.

Returns:

- (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.

Parameters:

  • aKey (Object)

    The key to remove.

Returns:

- (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.

Parameters:

  • keyArray (Array)

    An array of objects specifying the keys to remove.

Returns:

- (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.

Parameters:

  • otherDictionary (Hash)

    A dictionary containing the new entries.

Returns:

- (Object) setObject(anObject, forKey:aKey)

Adds a given key-value pair to the dictionary.

Parameters:

  • anObject (Object)

    The value for aKey. A strong reference to the object is maintained by the dictionary. Raises an NSInvalidArgumentException if anObject is nil. If you need to represent a nil value in the dictionary, use NSNull.

  • aKey (Object)

    The key for value. The key is copied (using copyWithZone:; keys must conform to the NSCopying protocol). Raises an NSInvalidArgumentException if aKey is nil. If aKey already exists in the dictionary anObject takes its place.

Returns:

- (Object) setObject(object, forKeyedSubscript:aKey)

Adds a given key-value pair to the dictionary. This method is identical to setObject:forKey:.

Parameters:

  • object (Object)

    The value for aKey. A strong reference to the object is maintained by the dictionary. Raises an NSInvalidArgumentException if anObject is nil. If you need to represent a nil value in the dictionary, use NSNull.

  • aKey (Object)

    The key for value. The key is copied (using copyWithZone:; keys must conform to the NSCopying protocol). Raises an NSInvalidArgumentException if aKey is nil. If aKey already exists in the dictionary anObject takes its place.

Returns:

- (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:.

Parameters:

  • value (Object)

    The value for key.

  • key (String)

    The key for value. Note that when using key-value coding, the key must be a string (see “Key-Value Coding Fundamentals”).

Returns: