3

"VoiceName" is an enum, declared like this:

enum VoiceName {
 PAD_RHYTHM,
 PAD_RHYTHM2,
 PAD_RHYTHM3,
 PEEPERS,
 ATMOSPHERE,
 IMPULSE,
 FAST_PULSE,
 HAIRYBALLS_PADS,
 KICK
};

The compiler doesn't seem to like me using it in a method signature like this:

-(void)pulseFiredWithSamplePosition:(float)position from: (VoiceName) voiceName;

It tells me expected ')' before 'VoiceName'. What's going on here?

morgancodes
  • 25,055
  • 38
  • 135
  • 187
  • 1
    possible duplicate of [Can an objective C method signature specify an enum type?](http://stackoverflow.com/questions/3723136/can-an-objective-c-method-signature-specify-an-enum-type) – Adam Rosenfield Sep 16 '10 at 01:45

3 Answers3

8

You can't use it "bare" like that without also specifying that it's an enum:

-(void)pulseFiredWithSamplePosition:(float)position from: (enum VoiceName) voiceName;

should work. If you want to avoid specifying it like that, you can typedef it:

typedef enum _VoiceName {
    PAD_RHYTHM,
    ....
} VoiceName;

then you'll be able to use just VoiceName as the argument type.

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
2

As of iOS6 and Mac OSX 10.8 you can use the NS_ENUM macro

typedef NS_ENUM(NSUInteger, VoiceName)
{
 PAD_RHYTHM,
 PAD_RHYTHM2,
 PAD_RHYTHM3,
 PEEPERS,
 ATMOSPHERE,
 IMPULSE,
 FAST_PULSE,
 HAIRYBALLS_PADS,
 KICK
};

NSUInteger can be replaced with whatever type your defining, then you could use your method as specified.

Cory
  • 2,302
  • 20
  • 33
1

Obj-C is based on C, not C++. C requires the enum keyword, as quixoto showed. C++ lets you omit it.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83