Is this the correct (or even a valid way) to use emums in Objective-C? i.e. The menuItem is not used but just defines a list add=1, load=2, list=3 etc.
enum menuItems {
add = 1 ,
save ,
load ,
list ,
removeAll ,
remove ,
quit
};
int optionSelect;
scanf("%d", &optionSelect);
switch (optionSelect) {
case add:
//...
break;
}
cheers gary
In this, the future, it's possibly also helpful to mention NS_ENUM
. You'd use it like:
typedef NS_ENUM(uint16_t, TYEnummedType)
{
TYEnummedType1,
TYEnummedType2
};
That has almost the same effect as a normal enum
and typedef
but explicitly dictates the integer type, which is really helpful if you ever want to pack these things off somewhere, be precise in your struct
alignment, amongst other uses.
It was added to the iOS SDK with version 6 and OS X with 10.8 but it's just a C macro and doesn't add anything that you couldn't do with vanilla typedef
and enum
, so there's no backwards compatibility to worry about. It exists only explicitly to tie the two things together.
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