Tuesday, December 29, 2009

Enum as a class property in Objective-C

For this post I'd like to show how you can define an enum property in Objective-C.
In a nutshell an enum is a datatype you create where in theory only certain values can be assigned to it and none else.

The code is pretty straight forward. Here it goes:

typedef enum
{
North, South, East, West
} Direction;

@interface MyClassName : NSObject
{
Direction direction;
}

@property(nonatomic) Direction direction;

In the above example only the values North, South, East, and West can be assigned to the direction property of a MyClassName instance.

2 comments:

Anonymous said...

nice explanation.Thank you

നിഴലുകൾ said...

it helped me...thnkx :)