Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I switch an enum in Objective-C

I can't seem to figure out how I should use a switch statement with my custom typedef enum. Xcode tells this error:

Statement requires expression of integer type (MyEnum *) is invalid.

this is my enum declared over the @interface in my header

typedef enum {
  A, B, C, D, E, F, G,
  Ab, Bb, Db, Eb, Gb,
  CSharp, DSharp, FSharp, GSharp
} Tones;

this is my property: @property(nonatomic) Tones *tone;

and this is my function to get the string value of the enum

- (NSString *)stringValue {

  switch (self.tone) {
    case GSharp:
      return @"G#";
    ...
  } 
}
like image 474
chrs Avatar asked Dec 04 '22 04:12

chrs


1 Answers

An enum has literal values (basically named integers), not object pointers. Thus it should be:

@property(nonatomic) Tones tone;
like image 59
Lukman Avatar answered Dec 28 '22 09:12

Lukman