Instance Method


Adds a given key-value pair to the dictionary.


- (void)setObject:(ObjectType)obj forKeyedSubscript:(id<NSCopying>)key;



The value for aKey. A strong reference to the object is maintained by the dictionary.

Passing nil will cause any object corresponding to aKey to be removed from the dictionary.


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


This method has the same behavior as the setObject:forKey: method.

You shouldn’t need to call this method directly. Instead, this method is called when setting an object for a key using subscripting.

id value = @"someValue";
mutableDictionary[@"someKey"] = value;

See Also

Adding Entries to a Mutable Dictionary

- setObject:forKey:

Adds a given key-value pair to the dictionary.

- setValue:forKey:

Adds a given key-value pair to the dictionary.

- addEntriesFromDictionary:

Adds to the receiving dictionary the entries from another dictionary.

- setDictionary:

Sets the contents of the receiving dictionary to entries in a given dictionary.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software