Bababa
Bababa

Reputation: 13

How to change value in typedef enum?

I have the next enum:

typedef enum {
    SignUp,
    LogIn
} TypeAction;

and after property in interface:

@property (assign, nonatomic) TypeAction * typeAction;

In button action I do:

- (IBAction)SignUp:(id)sender {
    self.typeAction = SignUp;
}

So, in another button action I try to compare as:

 - (IBAction)Check:(id)sender {
        if(self.typeAction = SignUp){
          //       
        }
    }

But I get nil inself.typeAction`

Upvotes: 0

Views: 277

Answers (1)

Leejay Schmidt
Leejay Schmidt

Reputation: 1203

This should probably be:

 - (IBAction)Check:(id)sender {
        if(self.typeAction == SignUp){
          //       
        }
    }

or, actually, you might want to change the if-statement to if(SignUp == self.typeAction), because the compiler would catch the == problem.

And your property declaration should be:

@property (assign, nonatomic) TypeAction typeAction;

assigns are not pointers, and you were setting self.typeAction to SignUp in that line of the if statement, which is then read as nil because it was seeing self.typeAction as a pointer, which is what was causing the error.

Upvotes: 3

Related Questions