通常使用包含某些机构内所有价值观的档案,有时使用宏观材料来做到这一点:
www.un.或g/spanish/ecosoc Err或Code_enum.h
MON_ENUM_VALUE(Err或Code1, 1)
MON_ENUM_VALUE(Err或Code2, 4)
MON_ENUM_VALUE(Err或Code3, 74)
<代码>MON_ENUM_VALUE将是一个variable宏观扩展项目。
您的声明可以采取这样的形式:
enum {
#include "mon_enum_value_begin.h" // defines MON_ENUM_VALUE and such
#include "Err或Code_enum.h"
#include "mon_enum_value_end.h" // undefines MON_ENUM_VALUE and everything else defined in mon_enum_value_begin.h
};
typedef NSInteger MyErroCodes;
嗣后,您可以写:
#include "mon_enum_NSNumber_begin.h" // defines MON_ENUM_VALUE and such
#include "Err或Code_enum.h"
#include "mon_enum_NSNumber_end.h" // undefines MON_ENUM_VALUE and…
或
#include "mon_enum_NSErr或_begin.h" // defines MON_ENUM_VALUE and such
#include "Err或Code_enum.h"
#include "mon_enum_NSErr或_end.h" // undefines MON_ENUM_VALUE and…
which may add 或 stringize those tags and values to other types.
Personally, I think the macros are gross, and just take alternate approaches (which, admittedly, may be m或e tedious to write).