Here is the definition of our EmployeeMap
once more:
{zcode:slice} dictionary<long, Employee> EmployeeMap; {zcode} |
The following code is generated for this definition:
{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:
{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.