Reputation: 23893
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
Reputation: 21808
Change "a"
to 'a'
and "A"
to 'A'
respectively. 'a'
is an integer type actually while "a"
is a string
Upvotes: 3
Reputation: 285200
the switch statement in Objective-C considers only integer values
Upvotes: 1