Up

NSDictionary class reference

Authors

Andrew Kachites McCallum (mccallum@gnu.ai.mit.edu)
Adam Fedor (fedor@boulder.colorado.edu)

Version: 1.101

Date: 2003/07/31 23:49:31

Copyright: (C) 1995, 1996, 1997 Free Software Foundation, Inc.


Contents -

  1. Software documentation for the NSDictionary class
  2. Software documentation for the NSMutableDictionary class

Software documentation for the NSDictionary class

NSDictionary : NSObject

Declared in:
Foundation/NSDictionary.h
Conforms to:
NSCoding
NSCopying
NSMutableCopying
Standards:

Description forthcoming.

Method summary

dictionary

+ (id) dictionary;

Description forthcoming.


dictionaryWithContentsOfFile:

+ (id) dictionaryWithContentsOfFile: (NSString*)path;

Returns a dictionary using the file located at path. The file must be a property list containing a dictionary as its root object.


dictionaryWithContentsOfURL:

+ (id) dictionaryWithContentsOfURL: (NSURL*)aURL;

Returns a dictionary using the contents of aURL. The URL must be a property list containing a dictionary as its root object.


dictionaryWithDictionary:

+ (id) dictionaryWithDictionary: (NSDictionary*)otherDictionary;

Returns a newly created dictionary with the keys and objects of otherDictionary. (The keys and objects are not copied.)


dictionaryWithObject:forKey:

+ (id) dictionaryWithObject: (id)object forKey: (id)key;

Returns a dictionary containing only one object which is associated with a key.


dictionaryWithObjects:forKeys:

+ (id) dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;

Description forthcoming.


dictionaryWithObjects:forKeys:count:

+ (id) dictionaryWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)count;

Returns a dictionary created using the given objects and keys. The two arrays must have the same size. The n th element of the objects array is associated with the n th element of the keys array.


dictionaryWithObjectsAndKeys:,...

+ (id) dictionaryWithObjectsAndKeys: (id)firstObject,...;

Returns a dictionary created using the list given as argument. The list is alernately composed of objects and keys. Thus, the list's length must be pair.


allKeys

- (NSArray*) allKeys;

Returns an array containing all the dictionary's keys.


allKeysForObject:

- (NSArray*) allKeysForObject: (id)anObject;

Returns an array containing all the dictionary's keys that are associated with anObject.


allValues

- (NSArray*) allValues;

Returns an array containing all the dictionary's objects.


count

- (unsigned) count;

Returns an unsigned integer which is the number of elements stored in the dictionary.


description

- (NSString*) description;

Returns the result of invoking -descriptionWithLocale:indent: with a nil locale and zero indent.


descriptionInStringsFileFormat

- (NSString*) descriptionInStringsFileFormat;

Returns the receiver as a text property list strings file format.
See [NSString -propertyListFromStringsFileFormat] for details.
The order of the items is undefined.


descriptionWithLocale:

- (NSString*) descriptionWithLocale: (NSDictionary*)locale;

Returns the result of invoking -descriptionWithLocale:indent: with a zero indent.


descriptionWithLocale:indent:

- (NSString*) descriptionWithLocale: (NSDictionary*)locale indent: (unsigned int)level;

Returns the receiver as a text property list in the traditional format.
See [NSString -propertyList] for details.
If locale is nil, no formatting is done, otherwise entries are formatted according to the locale, and indented according to level.
Unless locale is nil, a level of zero indents items by four spaces, while a level of one indents them by a tab.
If the keys in the dictionary respond to -compare: , the items are listed by key in ascending order. If not, the order in which the items are listed is undefined.


initWithContentsOfFile:

- (id) initWithContentsOfFile: (NSString*)path;

Initialises the dictionary with the contents of the specified file, which must contain a dictionary in property-list format.

In GNUstep, the property-list format may be either the OpenStep format (ASCII data), or the MacOS-X format (URF8 XML data)... this method will recognise which it is.

If there is a failure to load the file for any reason, the receiver will be released and the method will return nil.

Works by invoking [NSString -initWithContentsOfFile:] and [NSString -propertyList] then checking that the result is a dictionary.


initWithContentsOfURL:

- (id) initWithContentsOfURL: (NSURL*)aURL;

Initialises the dictionary with the contents of the specified URL, which must contain a dictionary in property-list format.

In GNUstep, the property-list format may be either the OpenStep format (ASCII data), or the MacOS-X format (URF8 XML data)... this method will recognise which it is.

If there is a failure to load the URL for any reason, the receiver will be released and the method will return nil.

Works by invoking [NSString -initWithContentsOfURL:] and [NSString -propertyList] then checking that the result is a dictionary.


initWithDictionary:

- (id) initWithDictionary: (NSDictionary*)otherDictionary;

Description forthcoming.


initWithDictionary:copyItems:

- (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy;

Initialise dictionary with the keys and values of otherDictionary. If the shouldCopy flag is YES then the values are copied into the newly initialised dictionary, otherwise they are simply retained.


initWithObjects:forKeys:

- (id) initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;

Initialises a dictionary created using the given objects and keys. The two arrays must have the same size. The n th element of the objects array is associated with the n th element of the keys array.


initWithObjects:forKeys:count:

- (id) initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)count;
This is a designated initialiser for the class.

Description forthcoming.


initWithObjectsAndKeys:,...

- (id) initWithObjectsAndKeys: (id)firstObject,...;

Initialises a dictionary created using the list given as argument. The list is alernately composed of objects and keys. Thus, the list's length must be pair.


isEqualToDictionary:

- (BOOL) isEqualToDictionary: (NSDictionary*)other;

Description forthcoming.


keyEnumerator

- (NSEnumerator*) keyEnumerator;

Return an enumerator object containing all the keys of the dictionary.


keysSortedByValueUsingSelector:

- (NSArray*) keysSortedByValueUsingSelector: (SEL)comp;

Description forthcoming.


objectEnumerator

- (NSEnumerator*) objectEnumerator;

Return an enumerator object containing all the objects of the dictionary.


objectForKey:

- (id) objectForKey: (id)aKey;

Returns the object in the dictionary corresponding to aKey, or nil if the key is not present.


objectsForKeys:notFoundMarker:

- (NSArray*) objectsForKeys: (NSArray*)keys notFoundMarker: (id)marker;

Description forthcoming.


valueForKey:

- (id) valueForKey: (NSString*)key;

Default implementation for this class is to return the value stored in the dictionary under the specified key, or nil if there is no value.


writeToFile:atomically:

- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile;

Writes the contents of the dictionary to the file specified by path. The file contents will be in property-list format... under GNUstep this is either OpenStep style (ASCII characters using \U hexadecimal escape sequences for unicode), or MacOS-X style (XML in the UTF8 character set).

If the useAuxiliaryFile flag is YES, the file write operation is atomic... the data is written to a temporary file, which is then renamed to the actual file name.

If the conversion of data into the correct property-list format fails or the write operation fails, the method returns NO, otherwise it returns YES.

NB. The fact that the file is in property-list format does not necessarily mean that it can be used to reconstruct the dictionary using the -initWithContentsOfFile: method. If the original dictionary contains non-property-list objects, the descriptions of those objects will have been written, and reading in the file as a property-list will result in a new dictionary containing the string descriptions.


writeToURL:atomically:

- (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile;

Writes the contents of the dictionary to the specified url. This functions just like -writeToFile:atomically: except that the output may be written to any URL, not just a local file.


Software documentation for the NSMutableDictionary class

NSMutableDictionary : NSDictionary

Declared in:
Foundation/NSDictionary.h
Standards:

Description forthcoming.

Method summary

dictionaryWithCapacity:

+ (id) dictionaryWithCapacity: (unsigned)numItems;

Description forthcoming.


addEntriesFromDictionary:

- (void) addEntriesFromDictionary: (NSDictionary*)otherDictionary;

Merges information from otherDictionary into the receiver. If a key exists in both dictionaries, the value from otherDictionary replaces that which was originally in the reciever.


initWithCapacity:

- (id) initWithCapacity: (unsigned)numItems;

Description forthcoming.


removeAllObjects

- (void) removeAllObjects;

Description forthcoming.


removeObjectForKey:

- (void) removeObjectForKey: (id)aKey;

Description forthcoming.


removeObjectsForKeys:

- (void) removeObjectsForKeys: (NSArray*)keyArray;

Description forthcoming.


setDictionary:

- (void) setDictionary: (NSDictionary*)otherDictionary;

Description forthcoming.


setObject:forKey:

- (void) setObject: (id)anObject forKey: (id)aKey;

Description forthcoming.


takeStoredValue:forKey:

- (void) takeStoredValue: (id)value forKey: (NSString*)key;

Default implementation for this class is equivalent to the -setObject:forKey: method unless value is nil, in which case it is equivalent to -removeObjectForKey:


takeValue:forKey:

- (void) takeValue: (id)value forKey: (NSString*)key;

Default implementation for this class is equivalent to the -setObject:forKey: method unless value is nil, in which case it is equivalent to -removeObjectForKey:



Up