---
name: "ObjDic"
section: "3"
platform: "linux"
package: "objpak-dev"
version: "1.1.1-1"
release: "Debian 1.3 (Bo)"
platforms: ["linux"]
url: "https://new.carta.tech/ObjDic"
---

# ObjDic(3)

## CLASS

**ObjDic**

## SUPERCLASS

ObjPak

## DESCRIPTION

Dictionaries (instances of the  **ObjDic**  class) are key-value tables : to each key object, a value object is associated.  The key can then be used to access the corresponding value.  There are a few special provisions for tables with  **ObjStr**  instances as keys.

## METHOD TYPES

**Creation**

new\
 copy\
 deepCopy\
 emptyYourself\
 freeContents\
 free\

**Interrogation**

size\
 isEmpty\
 includesKey:\

**Comparing**

hash\
 isEqual:\

**Indexed Access**

atKey:\
 atKeySTR:\
 atKey:put:\
 atKeySTR:put:\
 eachKey\
 eachValue\

**Printing**

printToFile:\

**NextStep Archiving**

write:\
 read:\

## METHODS

**new**

\+ **new**

Returns a new empty dictionary.

**copy**

\- **copy**

Returns a new copy of the dictionary.

**deepCopy**

\- **deepCopy**

Returns a new copy of the dictionary.  The members in the new dictionary are deep copies of the members in the original dictionary.

**emptyYourself**

\- **emptyYourself**

Removes all the keys and values of the dictionary (without freeing them).  Returns the receiver.

**freeContents**

\- **freeContents**

Removes and frees all the members of the receiver, but doesn't free the receiver itself.  Returns the receiver.

**free**

\- **free**

Frees the dictionary, but not its contents.  Returns  **nil.**   Do :

aDic = \[\[aDic freeObjects\] free\];\

if you want to free the dictionary and its contents.

**size**

\- (unsigned) **size**

Returns the number of key-value associations in the dictionary.

**isEmpty**

\- (BOOL) **isEmpty**

Whether the number of associations in the dictionary is equal to zero.

**includesKey:**

\- (BOOL) **includesKey:** *aKey*

Returns YES if there is an association with key matching  *aKey.*

**hash**

\- (unsigned) **hash**

Returns a hash value based on the receiver's address and the results of sending the  **hash**  message to the contents.

**isEqual:**

\- (BOOL) **isEqual:** *aDic*

Returns YES if  *aDic*  is a dictionary, and if its keys and values respond affirmatively to the message  **isEqual:**  when compared to the corresponding objects of the receiver's contents.

**atKey:**

\- **atKey:** *aKey*

Returns the value of the association matching  *aKey.*   Returns  **nil**  if the association is not found.

**atKeySTR:**

\- **atKeySTR:** (STR) *strKey*

Returns the value of the association matching  *strKey.*   Returns  **nil**  if the association is not found.

**atKey:put:**

\- **atKey:** *aKey* **put:** *anObject*

Associates  *aKey*  to  *anObject.*   Adds the objects to the dictionary.  If  *aKey*  was already in the dictionary, makes  *anObject*  the value for this key and returns the old value.  Otherwise returns  **nil.**

**atKeySTR:put:**

\- **atKeySTR:** (STR) *strKey* **put:** *anObject*

Associates  *strKey*  to  *anObject.*   Adds the objects to the dictionary.  If  *strKey*  was already in the dictionary, makes  *anObject*  the value for this key and returns the old value.  Otherwise returns  **nil.**

**eachKey**

\- **eachKey**

Returns a sequence of the key objects in the dictionary.

keys = \[aDic eachKey\];\
 while ((aKey = \[aSeq next\])) {\
\
     /\* do something \*/\
 }\
 keys = \[keys free\];\

**See also:**  eachValue

**eachValue**

\- **eachValue**

Returns a sequence of the value objects in the dictionary.

keys   = \[aDic eachKey\];\
 values = \[aDic eachValue\];\
 while ((aKey = \[aSeq next\])) {\
\
     aValue = \[values next\];\
\
     /\* do something \*/\
 }\
 keys   = \[keys free\];\
 values = \[values free\];\

**See also:**  eachKey

**printToFile:**

\- **printToFile:** (FILE \*) *aFile*

Prints a comma separated list of the key-value pairs by sending each individual object a  **printToFile:**  message.  Returns the receiver.

**write:**

\- **write:** (NXTypedStream \*) *stream*

Archives the dictionary and its set of key-values associations to  *stream.*

**read:**

\- **read:** (NXTypedStream \*) *stream*

Unarchives the dictionary and its set of key-values associations from  *stream.*
