How to declare an unknown listing in the title?

I know that you can use the word @class to declare an unknown class in the objective-c header file. Is there a way to declare an unknown enum inside the header class?

For example, is there a way to prevent a compilation error for someEnum ?

 #import <Foundation/Foundation.h> @class UnknownClass; @interface Foo @property (nonatomic, strong) UnknownClass *someObject; @property (nonatomic) UnknownEnum someEnum; @end 
+4
source share
2 answers

Yes, you can forward the enum declaration:

 enum things; 

However, I think that you will have problems if you start using compiler flags such as -pedantic , since I do not consider this part of the ISO standard. I also think that, like a declaration declaring a class, perhaps you are only using a pointer to it, since its size is unknown.

I never had to do this, and I prefer to include a header file that defines enum (and I don't think the enum forward declaration is cleaner than including a file).

Bottom line: Do not disturb .

+5
source

If for some reason you do not want to add the #import or #include directive for the header declaring enum , then simply enter it as something else. All enum types are pretty limited to some form of int . Just declare it similar. If you know you will get 0 or higher, you can use NSUinteger . If you know you will get negative numbers, use NSInteger . Any of these should be sufficient to declare your property.

In other words, named enumerations are nothing more than typdefs, because they use the value of an enumeration member or assign this value to a variable.

Another option is to make #ifndef to define the same type of def.

0
source

All Articles