Suchi
Suchi

Reputation: 10039

Objective C - Getter and setter properties for enum

I am a complete newbie at Objective-C. I have an enum as follows:

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType ;

I want to have getter and setter methods for it, such that if something happens, I set XLInboxManagedMethod to 1. How would I go about doing it?

Upvotes: 1

Views: 6481

Answers (3)

They are symbolic constants. You can not change it.

Upvotes: 0

Matt Wilding
Matt Wilding

Reputation: 20163

Your code is just defining an enum type. It's a static, compile-time constant that is not changed. You use enums by declaring an instance of one, then changing it to one of the constant values you defined. If your enum looks like:

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType;

Then your property could look like:

@property (nonatomic, assign) XLBadgeManagedType myEnum;

And its use may look like:

- (void)someMethod {

    self.myEnum = XLInboxManagedMethod;
    self.myEnum = XLDeveloperManagedMethod;
    // etc...
}

Upvotes: 14

MByD
MByD

Reputation: 137442

You do not change the values of enums. They stay as they are.

Upvotes: 2

Related Questions