Documentation for Ice 3.5. The latest release is Ice 3.7. Refer to the space directory for other releases.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 43 Current »

Here is the definition of our EmployeeMap once more:

Slice
dictionary<long, Employee> EmployeeMap;

The following code is generated for this definition:

Objective-C
typedef NSDictionary EXEmployeeMap;
typedef NSMutableDictionary EXMutableEmployeeMap;

Similar to sequences, Slice dictionaries map to type definitions for NSDictionary and NSMutableDictionary, with the names <module-prefix><Slice-name> and <module-prefix>Mutable<Slice-name>.

As a result, you can use the dictionary like any other NSDictionary, for example:

Objective-C
EXMutableEmployeeMap *em = [EXMutableEmployeeMap dictionary];
EXEmployee *e = [EXEmployee employee];
e.number = 42;
e.firstName = @"Stan";
e.lastName = @"Lippman";
[em setObject:e forKey:[NSNumber numberWithLong:e.number]];

e = [EXEmployee employee];
e.number = 77;
e.firstName = @"Herb";
e.lastName = @"Sutter";
[em setObject:e forKey:[NSNumber numberWithLong:e.number]];

To put a value type into a dictionary (either as the key or the value), you must use NSNumber as the object to hold the value. If you have a dictionary that uses a Slice enumeration as the key or the value, you must insert the enumerator as an NSNumber that holds an int.

To insert a null proxy or null class instance into a dictionary as a value, you must insert NSNull.

As a convenience feature, the Objective-C mapping also allows you to insert NSNull as the value of a dictionary if the value type of the dictionary is a string, structure, sequence, or dictionary. If you send such a dictionary to a receiver, the Ice run time marshals an empty string, default-initialized structure, empty sequence, or empty dictionary as the corresponding value to the receiver, respectively.

See Also
  • No labels