Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum type used in switch case error

I wrote following code in my app:

typedef enum{
    PasswordModeEnter = 1,
    PasswordModeSetNewPassword = 3,
    passwordModeVerify = 5,
    PasswordModeChange = 7,
    PasswordModeDisabled = 9
}PasswordModes;

And I instantiated an object named PasswordMode.

- (id)initWithPasswordMode:(PasswordModes *)passwordMode nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.PasswordMode = passwordMode;
    }
    return self;
}

I got an strange error when I wrote following code:

switch (self.PasswordMode) {
        case PasswordModeChange:
            //do something
            break;

        case PasswordModeDisabled:
            //do something
            break;
        case PasswordModeEnter:
            //do something
            break;

        case PasswordModeSetNewPassword:
            //do something
            break;
        case passwordModeVerify:
            //do something
            break;

        default:
            break;
    }

I got following error:

statement requires expression of integer type.

what is the problem and how can I solve it?

like image 845
aakpro Avatar asked Nov 29 '22 07:11

aakpro


2 Answers

The problem is with this

ProblemModes *

The * should be removed.

like image 133
aakpro Avatar answered Dec 04 '22 17:12

aakpro


PasswordModes is just an enum, your init method incorrectly indicates that it is a pointer. The init method signature should be as follows:

- (id)initWithPasswordMode:(PasswordModes)passwordMode nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;

Your property should be as follows:

@property (nonatomic,assign) PasswordMode passwordMode;
like image 35
DavidWeldon Avatar answered Dec 04 '22 16:12

DavidWeldon