Nurdin
Nurdin

Reputation: 23893

Objective-C - Expression is not an integer constant expression

I got this error message when trying to do switch.

/Users/xxxxx/Documents/iOS/xxxxx/main.m:83:14: Expression is not an integer constant expression

My code

char *anotherCharacter = "a";
        switch (*anotherCharacter) {
        case "a":
                NSLog(@"The letter a");
        case "A":
                NSLog(@"The letter A");
        default:
                NSLog(@"Not the letter A");
        }

Upvotes: 0

Views: 756

Answers (2)

Andrey Chernukha
Andrey Chernukha

Reputation: 21808

Change "a" to 'a' and "A" to 'A' respectively. 'a' is an integer type actually while "a" is a string

Upvotes: 3

vadian
vadian

Reputation: 285200

the switch statement in Objective-C considers only integer values

Upvotes: 1

Related Questions