Mikayil Abdullayev Mikayil Abdullayev -3 years ago 126
Objective-C Question

How do I achieve Enum myEnum=Enum.FirstValue in Objective-C

In C# I can use enums like this:

enum TrafficLight{Red,Yellow,Green};
TrafficLight light=TrafficLight.Yellow;

In Objective-C I write:

typedef enum trafficLight{

But if I want to assign a variable of TrafficLight to TrafficLight.Yellow, it's not possible. I can only write

TrafficLight light=Yellow;

Is it possible to access the constants inside the enum with dot notation in Objective-C too?

Answer Source

The common practice is as follows

enum {
typedef NSInteger TrafficLightColor;

TrafficLightColor color = TrafficLightColorYellow;

this way the Type of the parameter is the Beginning of its enum elements

Sorry i could not get the result you were looking for but this is the stardard practice as far as I have seen.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download