Adding, removing, and modifying entries – Apple WebObjects 3.5 User Manual
Page 204

Chapter 11
WebScript Programmer’s Quick Reference to Foundation Classes
204
– isEqual:
Returns YES if the specified object is a dictionary and has contents
equivalent to the receiver; NO, otherwise. Two dictionaries have
equivalent contents if they each hold the same number of entries and,
for a given key, the corresponding value objects in each dictionary
satisfy the
isEqual:
test.
– objectForKey:
Returns the object that corresponds to a specified key. For example,
the following code excerpt produces the NSString
sectionPreference
with
the contents “non-smoking”:
id preferences = [NSMutableDictionary
dictionaryWithObjects:@("window", "non-smoking", "747")
forKeys:@("seatAssignment", "section", "aircraft")];
id sectionPreference = [dictionary objectForKey:@"section"];
Adding, Removing, and Modifying Entries
Warning:
The following methods are not supported by NSDictionary. They are
available only to NSMutableDictionary objects.
– setObject:forKey:
Adds an entry to the receiver, consisting of a specified key and its
corresponding value object. If the receiver already has an entry for the
specified key, the previous value for that key is replaced with the
argument for
setObject:
. For example, the following code excerpt
produces the NSMutableDictionary
dictionary
with the value “non-
smoking” for the key “section” and the value “aisle” for the key
“seatAssignment.” Notice that the original value for “seatAssignment”
is replaced:
id dictionary = [NSMutableDictionary dictionaryWithDictionary:
@{"seatAssignment" = "window"}];
[dictionary setObject:@"non-smoking" forKey:@"section"];
[dictionary setObject:@"aisle" forKey:@"seatAssignment"];
It is an error to specify
nil
as an argument for
setObject:
or
forKey:
. You can’t
put
nil
in a dictionary as a key or as a value.
– addEntriesFromDictionary:
Adds the entries from a specified dictionary to the receiver. If both
dictionaries contain the same key, the receiver’s previous value for that
key is replaced with the new value.
– removeAllObjects
Empties the dictionary of its entries.