Znav |
---|
next | Objective-C Mapping for Constants |
---|
prev | Objective-C Mapping for Sequences |
---|
|
Here is the definition of our EmployeeMap
once more:
Wiki Markup |
---|
{zcode:slice}
dictionary<long, Employee> EmployeeMap;
{zcode} |
The following code is generated for this definition:
Wiki Markup |
---|
{zcode:objc}
typedef NSDictionary EXEmployeeMap;
typedef NSMutableDictionary EXMutableEmployeeMap;
{zcode} |
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:
Wiki Markup |
---|
{zcode:objc}
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]];
{zcode} |
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
Znav |
---|
next | Objective-C Mapping for Constants |
---|
prev | Objective-C Mapping for Sequences |
---|
|