How to use ENUM as a parameter for a method

I have the type that is specified 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 warn

"The ad" enum ServerType "will not be visible outside this function"

and worse when I try to convey it like this:

    NSArray *servers = [Server allServersForType:ServerTypeCount];

I get the error "Argument type" enum ServerType "incomplete"

What am I doing wrong?

Thanks in advance.

Rob

+4
source share
2 answers

You typed enum, so no need to specify again enum.

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

Update taken from comments:

Add an enumeration declaration to the .h file of the class declaring this method allServersForType:.

+7

:

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

, :

NSArray *servers = [Server allServersForType:ServerTypeCount];// Server here is your class name
-6

Source: https://habr.com/ru/post/1542395/


All Articles