Instance Method

setObject:forKeyedSubscript:

Adds a given key-value pair to the dictionary.

Declaration

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

Parameters

object

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.

aKey

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.

Discussion

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.