NS_ENUM gives compiler warning about forward references
c, compiler-warnings, enums, iphone, objective-c
Solution
Try:
typedef NS_ENUM(int, SomeEnumType){
SomeEnumType1,
SomeEnumType2,
SomeEnumType3,
SomeEnumType4
};
`NS_ENUM` won't do the typedef for you to declare the `SomeEnumType` type, you have to do it yourself.
Update: The reason why the warning shows up is due to the implementation of NS_ENUM. Let's see what it tries to do:
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
The problem line (I believe) is this:
enum _name : _type _name;
This is performing a forward declaration within the macro itself. Hence, with pedantic warnings, it's flagging the use of this up.
The pedantic warning is simply stating if you wanted to transition this to pure C, it would not be portable as it does not follow the standardisation of no forward declarations of enums. Within the realm of Xcode, Clang and LLVM (and the fact NS_ENUM is provided by Apple), you should be pretty safe.
Problem
Im using the spiffy new NS_ENUM to try and define an enum in my objective-c iOS project. I'm declaring the NS_ENUM in the header of a class like so: ``` NS_ENUM(int, SomeEnumType){ SomeEnumType1, SomeEnumType2, SomeEnumType3, SomeEnumType4 }; @interface Issue : NSObject .... ``` And im getting the compiler warning: ISO C forbids forward references to 'enum' types Now if i define the enum the (slightly) older traditional way like so: ``` typedef enum{ SomeEnumType1, SomeEnumType2, SomeEnumType3, SomeEnumType4 }SomeEnumType; @interface Issue : NSObject .... ``` in exactly the same place in the code the issue goes away. What am i doing wrong with NS_ENUM? EDIT: I corrected it by adding the typedef but its still giving a warning. I have turned on the pedantic compiler warnings. Is this just a case where its being too pedantic or is there a correct way that im missing?