Class CPDictionary

CPObject
    extended byCPDictionary

@implementation CPDictionary : CPObject

A dictionary is the standard way of passing around key-value pairs in the Cappuccino framework. It is similar to the Java map interface, except all keys are CPStrings and values can be any Cappuccino or JavaScript object.

If you are familiar with dictionaries in Cocoa, you'll notice that there is no CPMutableDictionary class. The regular CPDictionary has setObject: and removeObjectForKey: methods. In Cappuccino there is no distinction between immutable and mutable classes. They are all mutable.


Method Summary
+(id)dictionary
          Returns a new empty CPDictionary.
+(id)dictionaryWithDictionary:(CPDictionary)aDictionary
          Returns a new dictionary, initialized with the contents of aDictionary.
+(id)dictionaryWithObject:(id)anObject forKey:(id)aKey
          Creates a new dictionary with single key-value pair.
+(id)dictionaryWithObjects:(CPArray)objects forKeys:(CPArray)keys
          Creates a dictionary with multiple key-value pairs.
-(id)initWithCoder:(CPCoder)aCoder
          Initializes the dictionary by unarchiving the data from a coder.
-(id)initWithDictionary:(CPDictionary)aDictionary
          Initializes the dictionary with the contents of another dictionary.
-(id)initWithObjects:(CPArray)objects forKeys:(CPArray)keyArray
          Initializes the dictionary from the arrays of keys and objects.
-(CPArray)allKeys
          Returns an array of keys for all the entries in the dictionary.
-(CPArray)allValues
          Returns an array of values for all the entries in the dictionary.
-(int)count
          Returns the number of entries in the dictionary.
-(CPString)description
          Returns a human readable description of the dictionary.
-(void)encodeWithCoder:(CPCoder)aCoder
          Archives the dictionary to a provided coder.
-(CPEnumerator)keyEnumerator
          Returns an enumerator that enumerates over all the dictionary's keys.
-(CPEnumerator)objectEnumerator
          Returns an enumerator that enumerates over all the dictionary's values.
-(id)objectForKey:(CPString)aKey
          Returns the object for the entry with key aKey.
-(void)removeAllObjects
          Removes all the entries from the dictionary.
-(void)removeObjectForKey:(id)aKey
          Removes the entry for the specified key.
-(void)setObject:(id)anObject forKey:(id)aKey
          Adds an entry into the dictionary.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass


Method Detail

dictionary

+(id)dictionary
Returns a new empty CPDictionary.

dictionaryWithDictionary

+(id)dictionaryWithDictionary:(CPDictionary)aDictionary
Returns a new dictionary, initialized with the contents of aDictionary.
Parameters:
aDictionary - the dictionary to copy key-value pairs from
Returns:
the new CPDictionary

dictionaryWithObject

+(id)dictionaryWithObject:(id)anObject forKey:(id)aKey
Creates a new dictionary with single key-value pair.
Parameters:
anObject - the object for the paring
aKey - the key for the pairing
Returns:
the new CPDictionary

dictionaryWithObjects

+(id)dictionaryWithObjects:(CPArray)objects forKeys:(CPArray)keys
Creates a dictionary with multiple key-value pairs.
Parameters:
objects - the objects to place in the dictionary
keys - the keys for each of the objects
Throws:
CPInvalidArgumentException - if the number of objects and keys is different
Returns:
the new CPDictionary

initWithCoder

-(id)initWithCoder:(CPCoder)aCoder
Initializes the dictionary by unarchiving the data from a coder.
Parameters:
aCoder - the coder from which the data will be unarchived.
Returns:
the initialized dictionary

initWithDictionary

-(id)initWithDictionary:(CPDictionary)aDictionary
Initializes the dictionary with the contents of another dictionary.
Parameters:
aDictionary - the dictionary to copy key-value pairs from
Returns:
the initialized dictionary

initWithObjects

-(id)initWithObjects:(CPArray)objects forKeys:(CPArray)keyArray
Initializes the dictionary from the arrays of keys and objects.
Parameters:
objects - the objects to put in the dictionary
keyArray - the keys for the objects to put in the dictionary
Throws:
CPInvalidArgumentException - if the number of objects and keys is different
Returns:
the initialized dictionary

allKeys

-(CPArray)allKeys
Returns an array of keys for all the entries in the dictionary.

allValues

-(CPArray)allValues
Returns an array of values for all the entries in the dictionary.

count

-(int)count
Returns the number of entries in the dictionary

description

-(CPString)description
Returns a human readable description of the dictionary.

encodeWithCoder

-(void)encodeWithCoder:(CPCoder)aCoder
Archives the dictionary to a provided coder.
Parameters:
aCoder - the coder to which the dictionary data will be archived.

keyEnumerator

-(CPEnumerator)keyEnumerator
Returns an enumerator that enumerates over all the dictionary's keys.

objectEnumerator

-(CPEnumerator)objectEnumerator
Returns an enumerator that enumerates over all the dictionary's values.

objectForKey

-(id)objectForKey:(CPString)aKey
Returns the object for the entry with key aKey.
Parameters:
aKey - the key for the object's entry
Returns:
the object for the entry

removeAllObjects

-(void)removeAllObjects
Removes all the entries from the dictionary.

removeObjectForKey

-(void)removeObjectForKey:(id)aKey
Removes the entry for the specified key.
Parameters:
aKey - the key of the entry to be removed

setObject

-(void)setObject:(id)anObject forKey:(id)aKey
Adds an entry into the dictionary.
Parameters:
anObject - the object for the entry
aKey - the entry's key

Created on Sat Sep 13 14:15:43 PDT 2008