I've defined an enum at the top of my class header:
enum PresetSeq{kSeqClear=0, kSeqAllBeats, kSeqAllTicks};
But when I try to declare a method for that class using the enum.
-(void)quickSetSeq:(PresetSeq)pattern forChannel:(long)ch;
I get the error: expected ')' before 'PresetSeq'
If I typedef the enum instead:
typedef enum {kSeqClear=0, kSeqAllBeats, kSeqAllTicks} PresetSeq;
Then the compiler is happy, but I don't remember having to do that in C/C++.
Do enums have to be typedef's in Obj-C?
Thanks
Steve
P.S. - I saw other posts about Obj-C enums, but not why this simple case fails.
These are C enum
s. (Remember Objective-C is just a strict superset of C).
To define an enumerated type, you must use typedef
.
However, if you do not need to have a standalone type (without the enum
prefix) to collectively refer to that enum, then you do not need typedef
and you can just declare it like this:
enum PresetSeq {
kSeqClear,
kSeqAllBeats,
kSeqAllTicks
};
So, in your case, you can do it either way:
typedef enum {
kSeqClear,
kSeqAllBeats,
kSeqAllTicks
} PresetSeq;
-(void)quickSetSeq:(PresetSeq)pattern forChannel:(long)ch;
Or without typedef
and using the enum PresetSeq
syntax as shown above:
-(void)quickSetSeq:(enum PresetSeq)pattern forChannel:(long)ch;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With