Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ENUM as a parameter to a Method

I have a type defined like this in my Prefix.pch file.

typedef NS_ENUM(NSUInteger, ServerType) {
ServerType0 = 0,
ServerType1,
ServerTypeCount
};

I have a method declaration like this:

+ (NSArray *)allServersForType:(enum ServerType)serverType;

But I am getting warning

"Declaration of 'enum ServerType' will not be visible outside of this function"

and worse when I try to pass it like this:

    NSArray *servers = [Server allServersForType:ServerTypeCount];

I get an error "Argument type 'enum ServerType' is incomplete"

What am I doing wrong?

Thanks in advance.

Rob

like image 694
Rob Avatar asked Sep 30 '22 16:09

Rob


1 Answers

You've typedefed the enum so no need to specify enum again.

+ (NSArray *)allServersForType:(ServerType)serverType;

Update taken from comments:

Add the declaration of the enum to the .h file of the class that declares this allServersForType: method.

like image 150
lucianomarisi Avatar answered Oct 11 '22 11:10

lucianomarisi