Objective C - Constants with behaviour
- by Akshay
Hi,
I'm new to Objective C. I am trying to define Constants which have behavior associated with them. So far I have done -
@interface Direction : NSObject {
NSString *displayName;
}
-(id)initWithDisplayName:(NSString *)aName;
-(id)left; // returns West when North
-(id)right; // return East when North
@end
@implementation Direction
-(id)initWithDisplayName:(NSString *)aName
{
if(self = [super init])
{
displayName = aName;
}
return self;
}
-(id)left {};
-(id)right {};
@end
Direction* North = [Direction initWithDisplayName:@"North"]; // error - initializer element is not constant.
This approach results in the indicated error. Is there a better way of doing this in Objective C.