Doubt about NS_ENUM

0

I have the following question about NS_ENUM I'm creating one with three options:

typedef NS_ENUM(NSInteger, VersionStatus) {

   OPTION1,

   OPTION2,

   OPTION3

};

How do I use else within a switch?

How will the comparison parameter come from a Service? Do they follow the creation order?

Being

OPTION1 = 1 (ou zero) , OPTION2 = 2,  OPTION3
    
asked by anonymous 26.02.2016 / 20:51

1 answer

1

enum (or enumerated value) is a form, inherited from C, of declaring constant values.

Your base syntax is:

typedef NS_ENUM(NSInteger, ASRestaurantStatus) {
    ASRestaurantStatusOpen,
    ASRestaurantStatusClosed,
    ASRestaurantStatusRenovating
};

The first element, without value definition, is always zero and the next element follows the sequence.

To use within a switch, nothing changes relative to a common integer, for example:

switch (currentStatus) {
    case ASRestaurantStatusRenovating: {
    } break;

    case ASRestaurantStatusClosed: {
    } break;

    case ASRestaurantStatusOpen: {
    } break;
}

They can be seen, in essence, as just a "safe" definition of something.

    
03.04.2016 / 23:32