tags:

views:

68

answers:

1

I'm making the jump from Java to Objective-C. I'm wondering if there is a concept analogous to Java's enums, that supports implementations of methods. I realize Objective-C has plain old C enumerations, but those are really just ints.

I'm looking to prevent switch-yards -- Java enums would be perfect.

+6  A: 

Objective-C is just C with some additional markup for objects, no new types have been added.

That means, no.

For mutual exclusive flags, Apple uses strings.

header.h

extern NSString * const kNSSomeFlag;
extern NSString * const kNSOtherFlag;
extern NSString * const kNSThirdFlag ;

code.m

NSString * const kNSSomeFlag = @"kNSSomeFlag";
NSString * const kNSOtherFlag = @"kNSOtherFlag";
NSString * const kNSThirdFlag = @"kNSThirdFlag";

…

void myFunction(NSString *flag)
{
    if (flag == kNSSomeFlag) {
        // the code
    }
}

An example of this can be found in the NSDistributedNotificationCenter.

Georg