I donโ€™t understand the reason for the "Expected Type" compilation error in the method declaration when the type is defined

This code will not compile and generates the "Expected Type" error message. Since the type is declared just above, I do not understand why.

enum TMyType { Etype1, Etype2 }; @interface Factory : NSObject + (void) foo: (TMyType) actionType; @end 
+7
source share
2 answers

To define a custom type, the correct way is with typedef.

Try ...

 typedef enum { Etype1, Etype2 } TMyType; 

EDIT: Shortly after this question was asked and answered, Apple released a new way to do the listed data types. Below is a detailed article about this.

 typedef NS_ENUM(NSInteger, TMyType) { Etype1, Etype2 }; 
+7
source
 + (void) foo: (enum TMyType) actionType; 

or use .mm (and ask a question using objective-c++ ).

+2
source

All Articles