I have used typedef NS_ENUM
to reorganise data constants in old code. Using an approach found here every typedef
is declared in a single .h
file that can be imported to any class in the project. Content of the .h file is wrapped in a message to the compiler. This works nicely for int
variables.
MYCharacterType.h
#ifndef MYCharacterType_h
#define MYCharacterType_h
typedef NS_ENUM(NSInteger, MARGIN)
{
MARGIN_Top = 10,
MARGIN_Side = 10,
MARGIN_PanelBaseLine = 1
};
...
#endif /* SatGamEnumType_h */
But Xcode complains when I try to include float
variables
“Non-Integral type ’NSNumber’ is an invalid underlying type’
e.g.
typedef NS_ENUM(NSNumber, LINE_WIDTH) {
LINE_WIDTH_Large = 1.5,
LINE_WIDTH_Medium = 1.0,
LINE_WIDTH_Small = 0.5,
LINE_WIDTH_Hairline = 0.25
};
I get the same message whether I use NSValue
or NSNumber
so I suspect typedef NS_ENUM
is not the way to define float
variables (or at least the way I am using it).
The approach in this answer would only allow me to do what I have already organised in one file but does not offer a way to reorganise float
variables in the same file. Could someone please explain how to do this so all variables are defined in one .h
file regardless of their type ? Thanks
SOLUTION
This was answered by rmaddy after I approached the question differently.