How to define several variable types in one .h file using `typedef NS_ENUM`

后端 未结 1 519
甜味超标
甜味超标 2021-01-27 20:40

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

1条回答
  •  [愿得一人]
    2021-01-27 21:28

    Defining different enums in one .h .. like just add it one file.

    typedef NS_ENUM(NSInteger, MARGIN)
    {
        MARGIN_Top                          =  10,
        MARGIN_Side                         =  10,
        MARGIN_PanelBaseLine                =   1
    };
    
    
    typedef NS_ENUM(long, ENUM_2)
    {
        ENUM_2_1    = 10,
        ENUM_2_2    = 20,
        ENUM_2_3    = 30,
    };
    
    typedef NS_ENUM(long, ENUM_3)
    {
        ENUM_3_1    = 10,
        ENUM_3_2    = 20,
        ENUM_3_3    = 30,
    };
    
    // And so on as many as you want
    

    And your second question, Enums can only be of the integral data types like, int, long, long long, unsigned int, short etc... You can't use any Non-Integral types like float or double or not even any objective c types.

    You can do enum mapping for float values like this https://stackoverflow.com/a/8867169/1825618

    0 讨论(0)
提交回复
热议问题