【发布时间】:2013-11-26 12:13:28
【问题描述】:
我想知道,是否可以检索枚举中所有项目的列表?
例如我定义的:
typedef enum YouJustUnlocked {
Unlocked_A,
Unlocked_B,
//etc... many more
Unlocked_Nothing,
}YouJustUnlocked;
有没有办法在新定义的枚举类型 YouJustUnlocked 中检索所有“项目”(不准确的词)的列表?
Objective-C 支持吗?
我想要类似的东西:
NSArray * array = [YouJustUnlocked returnAllItemsInWrapperObjectForm];
YouJustUnlocked item = (YouJustUnlocked) [array objectAtIndex:0];
//Assuming that array will contain some sort of wrapper object (like NSInteger)
【问题讨论】:
-
NSInteger 不是对象,不能直接放入数组中。
-
我知道,但这就是为什么我要问 Objective C 语义中是否有一个特性,它返回一个通用包装器(例如 NSInteger),它包装了我定义的枚举。鉴于枚举是由 int 定义的,它是有意义的。此外,Objective-C 和 iOS 使用编码器功能,在那里,对枚举进行编码,是使用 encodeAsInt 功能的常见做法。所以我想知道是否有类似的东西。
-
我不同意最后的投票。如果您阅读它,这个问题就很清楚了。
标签: objective-c arrays types enums wrapper