Creating dictionaries – Apple WebObjects 3.5 User Manual
Page 202

Chapter 11
WebScript Programmer’s Quick Reference to Foundation Classes
202
Creating Dictionaries
The methods in this section are class methods, as denoted by the plus sign (+).
You use class methods to send messages to a class—in this case, NSDictionary
and NSMutableDictionary. For more information on class methods, see
“Sending a Message to a Class” (page 172).
+ dictionary
Returns an empty dictionary. Usually used to create
NSMutableDictionaries. NSDictionaries created with this method are
permanently empty.
// Most common use
id mutableDictionary = [NSMutableDictionary dictionary];
// May not be what you want
id dictionary = [NSDictionary dictionary];
+ dictionaryWithObjects:forKeys:
Returns a dictionary containing entries constructed from the contents
of a specified array of objects and a specified array of keys. The two
arrays must have the same number of elements.
id preferences = [NSMutableDictionary
dictionaryWithObjects:@("window", "non-smoking", "747")
forKeys:@("seatAssignment", "smoking", "aircraft")];
+ dictionaryWithObjectsAndKeys:
Returns a dictionary containing entries constructed from a specified set
of objects and keys. This method takes a variable number of
arguments: a list of alternating objects and keys ending with
nil
.
id customerPreferences = [NSDictionary dictionaryWithObjectsAndKeys:
seatingPreference, @"seatAssignment",
smokingPreference, @"smoking",
aircraftPreference, @"aircraft", nil];
+ dictionaryWithDictionary:
Returns a dictionary containing the contents of a specified dictionary.
Usually used to create an NSMutableDictionary from an immutable
NSDictionary.
+ dictionaryWithContentsOfFile:
Returns a dictionary initialized from the contents of a specified file.
The specified file can be a full or relative pathname; the file that it
names must contain a string representation of a dictionary, such as that
produced by the
writeToFile:atomically:
method.
See also
description
(page 205) .