English 中文(简体)
国家航空航天研究所的所有价值?
原标题:All values of an enum in an NSArray?

然而,我有一大类,持有我的错误代码。

问题是,这些问题不是顺序的。

enum{
    ErrorCode1                = 1,
    ErrorCode2                = 4,
    ErrorCode3                = 74
}; typedef NSInteger  MyErroCodes;

而且,也许还有50部法典+,因此,我真的不想重复数据或人工操作数据,这是我迄今为止在我搜查中看到的情况。 任何帮助都将受到高度赞赏。

最佳回答

只是在汇编时间才存在。 你们的MyErrorCodes的事例是明显的愤怒,ErrorCodeN的价值观只是简单的愤怒。 无法从您的 en中提取元数据(别处,或许有 de,但你不想去......)。

我建议:

  • Create a small script (Python, Perl or whatnot) to generate functions that map the numeric code to string values. In XCode, you can even run code generators during the compilation phase if you really want.
  • Use metaprogramming or preprocessor macros to generate these functions during compilation. This requires some thought, but it can be done.
问题回答

通常使用包含某些机构内所有价值观的档案,有时使用宏观材料来做到这一点:

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).





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签