views:

28

answers:

3

I want to have a enum as a parameter of my function. Would this work?

(UIFont*) myMethodName:(UITableViewCellStyle) cellStyle {
    //...
    if (cellStyle == UITableViewCellStyleValue2)
        // ...
}

Then I would call the method like this way

UIFont *resultFont = [self myMethodName:UITableViewCellStyleSubtitle];

Only the following parameters should be allowed: UITableViewCellStyleDefault, UITableViewCellStyleValue1, UITableViewCellStyleValue2, UITableViewCellStyleSubtitle

Is it possible?

+1  A: 

Sure:

typedef enum _MyType {
    type_a = -1,
    type_b = 0,
    type_c = 1,
} MyType;

...

- (void) someMethod:(MyType)type {
    if (type == type_a) ...
}
kovpas
A: 

Yes, it's possible.

(This feels like an unnecessarily short answer but I can't think of anything else to add!)

Stephen Darlington
That's all I wanted to know ;)
testing
+3  A: 
KennyTM