Preliminary documentation for Ice 3.7.1 Beta. Do not use in production applications. Refer to the space directory for other releases.

The Objective-C mapping for optional data members in Slice classes and exceptions adds an extra boolean instance variable as well as two selectors for testing if the optional is set and clearing its value. The argument for the optional data member in the convenience constructor is mapped according to the optional parameter mapping for Slice operations. Consider the following Slice definition:

Slice
class C
{
    string name;
    optional(2) string alternateName;
    optional(5) bool active;
}

The generated Objective-C code provides the following API:

Objective-C
@interface testC : ICEObject
{
    NSString *name;
    NSString *alternateName;
    BOOL has_alternateName__;
    BOOL active;
    BOOL has_active__;
}
@property(nonatomic, strong) NSString *name;
@property(nonatomic, strong) NSString *alternateName;
@property(nonatomic, assign) BOOL active;
-(id) init:(NSString*)name alternateName:(id)alternateName active:(id)active;
+(id) c:(NSString*)name alternateName:(id)alternateName active:(id)active;
+(id) c;
-(void)setAlternateName:(NSString*)alternateName;
-(BOOL)hasAlternateName;
-(void)clearAlternateName;
-(void)setActive:(BOOL)active;
-(BOOL)hasActive;
-(void)clearActive;
@end

Note that calling a get method or accessing the property when the value is not currently set returns an undefined value.

See Also

  • No labels