Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: where and how should I declare enums?

Good day, friends. I'm newbie in Objective-C. I'm wanting to use enum in my class and make it public. I've understand how to declare enums (http://stackoverflow.com/questions/1662183/using-enum-in-objective-c), but I don't understand where should I declare them.

I've tried:

@interface MyFirstClass : NSObject {
typedef enum myTypes {VALUE_A, VALUE_B, VALUE_C} MyTypes;
}

or:

@interface MyFirstClass : NSObject {
@public
   typedef enum myTypes {VALUE_A, VALUE_B, VALUE_C} MyTypes;
}

But compiler throws error: "expected specifier-qualifier-list before typedef".

What's wrong?

like image 752
QuickNick Avatar asked Aug 02 '11 11:08

QuickNick


1 Answers

You can create a header file (*.h) and do following to match your enum variable.

//  EnumConstants.h


#ifndef EnumConstants_h
#define EnumConstants_h

typedef enum {
    VEHICLE,
    USERNAME
} EDIT_TYPE;

typedef enum {
    HIGH_FLOW,
    STANDARD_FLOW
} FLOW_TYPE;


#endif

Uses:

#import "EnumConstants.h"

UISwitch *onOffSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.tableview.frame.size.width-75, 26, 0, 0)];
onOffSwitch.tag =STANDARD_FLOW;
like image 77
Rajan Twanabashu Avatar answered Oct 01 '22 18:10

Rajan Twanabashu