API 0.9.5
CPDictionary Class Reference

A mutable key-value pair collection. More...

#import <CPDictionary.h>

Inheritance diagram for CPDictionary:

List of all members.

Instance Methods

(void) - addEntriesFromDictionary:
(CPArray- allKeys
(CPArray- allKeysForObject:
(CPArray- allValues
(BOOL) - containsKey:
(CPDictionary- copy
(int) - count
(CPString- description
(void) - encodeWithCoder:
(id) - initWithCoder:
(id) - initWithDictionary:
(id) - initWithObjects:forKeys:
(id) - initWithObjectsAndKeys:
(CPDictionary- inverseChangeDictionary
(BOOL) - isEqual:
(BOOL) - isEqualToDictionary:
(CPEnumerator- keyEnumerator
(CPArray- keysSortedByValueUsingSelector:
(CPEnumerator- objectEnumerator
(id) - objectForKey:
(void) - removeAllObjects
(void) - removeObjectForKey:
(void) - removeObjectsForKeys:
(void) - setObject:forKey:
(void) - setValue:forKey:
(id) - valueForKey:

Class Methods

(id) + alloc
(id) + dictionary
(id) + dictionaryWithDictionary:
(id) + dictionaryWithJSObject:
(id) + dictionaryWithJSObject:recursively:
(id) + dictionaryWithObject:forKey:
(id) + dictionaryWithObjects:forKeys:
(id) + dictionaryWithObjectsAndKeys:

Detailed Description

A mutable key-value pair collection.

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:forKey: and -removeObjectForKey: methods. In Cappuccino there is no distinction between immutable and mutable classes. They are all mutable.

Definition at line 2 of file CPDictionary.h.


Method Documentation

- (void) addEntriesFromDictionary: (CPDictionary aDictionary

Take all the key/value pairs in aDictionary and apply them to this dictionary.

Definition at line 554 of file CPDictionary.j.

- (CPArray) allKeys

Returns an array of keys for all the entries in the dictionary.

Definition at line 326 of file CPDictionary.j.

- (CPArray) allKeysForObject: (id)  anObject

Returns a new array containing the keys corresponding to all occurrences of a given object in the receiver.

Parameters:
anObjectThe value to look for in the receiver.
Returns:
A new array containing the keys corresponding to all occurrences of anObject in the receiver. If no object matching anObject is found, returns an empty array.

Each object in the receiver is sent an isEqual: message to determine if it's equal to anObject. If the check for isEqual fails a check is made to see if the two objects are the same object. This provides compatibility for JSObjects.

Definition at line 353 of file CPDictionary.j.

+ (id) alloc

Definition at line 81 of file CPDictionary.j.

- (CPArray) allValues

Returns an array of values for all the entries in the dictionary.

Definition at line 334 of file CPDictionary.j.

- (BOOL) containsKey: (id)  aKey

Definition at line 578 of file CPDictionary.j.

- (CPDictionary) copy

return a copy of the receiver (does not deep copy the objects contained in the dictionary).

Definition at line 310 of file CPDictionary.j.

- (int) count

Returns the number of entries in the dictionary

Definition at line 318 of file CPDictionary.j.

- (CPString) description

Returns a human readable description of the dictionary.

Definition at line 573 of file CPDictionary.j.

+ (id) dictionary

Returns a new empty CPDictionary.

Definition at line 91 of file CPDictionary.j.

+ (id) dictionaryWithDictionary: (CPDictionary aDictionary

Returns a new dictionary, initialized with the contents of aDictionary.

Parameters:
aDictionarythe dictionary to copy key-value pairs from
Returns:
the new CPDictionary

Definition at line 101 of file CPDictionary.j.

+ (id) dictionaryWithJSObject: (JSObject)  object

Creates a dictionary with multiple key-value pairs.

Parameters:
JavaScriptobject
Returns:
the new CPDictionary

Definition at line 134 of file CPDictionary.j.

+ (id) dictionaryWithJSObject: (JSObject)  object
recursively: (BOOL)  recursively 

Creates a dictionary with multiple key-value pairs, recursively.

Parameters:
JavaScriptobject
Returns:
the new CPDictionary

Definition at line 144 of file CPDictionary.j.

+ (id) dictionaryWithObject: (id)  anObject
forKey: (id)  aKey 

Creates a new dictionary with single key-value pair.

Parameters:
anObjectthe object for the paring
aKeythe key for the pairing
Returns:
the new CPDictionary

Definition at line 112 of file CPDictionary.j.

+ (id) dictionaryWithObjects: (CPArray objects
forKeys: (CPArray keys 

Creates a dictionary with multiple key-value pairs.

Parameters:
objectsthe objects to place in the dictionary
keysthe keys for each of the objects
Exceptions:
CPInvalidArgumentExceptionif the number of objects and keys is different
Returns:
the new CPDictionary

Definition at line 124 of file CPDictionary.j.

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

Creates and returns a dictionary constructed by a given pairs of keys and values.

Parameters:
firstObjectfirst object value
...key for the first object and ongoing value-key pairs for more objects.
Exceptions:
CPInvalidArgumentExceptionif the number of objects and keys is different
Returns:
the new CPDictionary

Assuming that there's no object retaining in Cappuccino, you can create dictionaries same way as with alloc and initWithObjectsAndKeys: var dict = [CPDictionary dictionaryWithObjectsAndKeys: "value1", @"key1", @"value2", @"key2"];

Note, that there's no final nil like in Objective-C/Cocoa.

See also:
[CPDictionary - initWithObjectsAndKeys:]

Definition at line 216 of file CPDictionary.j.

- (void) encodeWithCoder: (CPCoder aCoder

Archives the dictionary to a provided coder.

Parameters:
aCoderthe coder to which the dictionary data will be archived.

Definition at line 601 of file CPDictionary.j.

- (id) initWithCoder: (CPCoder aCoder

Definition at line 592 of file CPDictionary.j.

- (id) initWithDictionary: (CPDictionary aDictionary

Initializes the dictionary with the contents of another dictionary.

Parameters:
aDictionarythe dictionary to copy key-value pairs from
Returns:
the initialized dictionary

Definition at line 229 of file CPDictionary.j.

- (id) initWithObjects: (CPArray objects
forKeys: (CPArray keyArray 

Initializes the dictionary from the arrays of keys and objects.

Parameters:
objectsthe objects to put in the dictionary
keyArraythe keys for the objects to put in the dictionary
Exceptions:
CPInvalidArgumentExceptionif the number of objects and keys is different
Returns:
the initialized dictionary

Definition at line 247 of file CPDictionary.j.

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

Creates and returns a dictionary constructed by a given pairs of keys and values.

Parameters:
firstObjectfirst object value
...key for the first object and ongoing value-key pairs for more objects.
Exceptions:
CPInvalidArgumentExceptionif the number of objects and keys is different
Returns:
the new CPDictionary

You can create dictionaries this way: var dict = [[CPDictionary alloc] initWithObjectsAndKeys: "value1", @"key1", @"value2", @"key2"];

Note, that there's no final nil like in Objective-C/Cocoa.

Definition at line 279 of file CPDictionary.j.

- (CPDictionary) inverseChangeDictionary

Definition at line 125 of file CPKeyValueObserving.j.

- (BOOL) isEqual: (id)  anObject

Definition at line 433 of file CPDictionary.j.

- (BOOL) isEqualToDictionary: (CPDictionary aDictionary

Compare the receiver to this dictionary, and return whether or not they are equal.

Definition at line 403 of file CPDictionary.j.

- (CPEnumerator) keyEnumerator

Returns an enumerator that enumerates over all the dictionary's keys.

Definition at line 387 of file CPDictionary.j.

- (CPArray) keysSortedByValueUsingSelector: (SEL)  theSelector

Definition at line 374 of file CPDictionary.j.

- (CPEnumerator) objectEnumerator

Returns an enumerator that enumerates over all the dictionary's values.

Definition at line 395 of file CPDictionary.j.

- (id) objectForKey: (id)  aKey

Returns the object for the entry with key aKey.

Parameters:
aKeythe key for the object's entry
Returns:
the object for the entry

Definition at line 472 of file CPDictionary.j.

- (void) removeAllObjects

Removes all the entries from the dictionary.

Definition at line 503 of file CPDictionary.j.

- (void) removeObjectForKey: (id)  aKey

Removes the entry for the specified key.

Parameters:
aKeythe key of the entry to be removed

Definition at line 512 of file CPDictionary.j.

- (void) removeObjectsForKeys: (CPArray keysForRemoval

Removes each entry in allKeys from the receiver.

Parameters:
allKeysan array of keys that will be removed from the dictionary

Definition at line 521 of file CPDictionary.j.

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

Adds an entry into the dictionary.

Parameters:
anObjectthe object for the entry
aKeythe entry's key

Definition at line 546 of file CPDictionary.j.

- (void) setValue: (id)  aValue
forKey: (CPString aKey 

Reimplemented from CPObject.

Definition at line 262 of file CPKeyValueCoding.j.

- (id) valueForKey: (CPString aKey

Reimplemented from CPObject.

Definition at line 254 of file CPKeyValueCoding.j.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines