Doubt about NS_ENUM

Asked

Viewed 23 times

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 Lse inside a switch?

Where the comparison parameter will come from a Service? they follow the order of creation?

Being

OPTION1 = 1 (ou zero) , OPTION2 = 2,  OPTION3

1 answer

1

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

Its basic syntax is:

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

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

To use inside 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 their essence, as just a "safe" definition of something.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.