IOS - Is this a task for listings?

If I want to implement the following code, would the enums be listed? I looked through a few questions about the listings, but I'm still a little sure.

if (dayOfWeek == Monday)
{
    // Do something
}
else if (dayOfWeek == Tuesday || dayOfWeek == Wednesday)
{
    // Do something else
}

If this seems correct, how can I start the enumeration initialization? Will it be included in the header or implementation file?

+2
source share
2 answers

If I want to implement the following code, are enums allowed?

Not describing alternatives in too much detail - Yes.

how would I start initializing an enumeration?

I usually declare an enumeration in C like this:

typedef enum MONDayOfWeek {
  MONDayOfWeek_Undefined = 0,
  MONDayOfWeek_Monday,
  MONDayOfWeek_Tuesday,
  MONDayOfWeek_Wednesday,
  MONDayOfWeek_Thursday,
  MONDayOfWeek_Friday,
  MONDayOfWeek_Saturday,
  MONDayOfWeek_Sunday
} MONDayOfWeek;

// in use:
MONDayOfWeek day = MONDayOfWeek_Monday;

MONwill be your library or organization prefix. DayOfWeekwill be the name of the enumeration in the library, then the values ​​will be added.

, .

?

, , , .

+7

, , SO-, :

typedef Objective-C?

typedef enum {
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
} DayOfTheWeek;

, , , , .

+2

All Articles