将枚举值保存到字典中 [英] Saving enum values into a dictionary
本文介绍了将枚举值保存到字典中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将枚举值保存到字典中?
How does one save an enum value to a dictionary?
当我尝试以下操作
enum someEnum
{
field0 = 0,
field1 = 1,
field2 = 2,
};
enum someEnum someEnumObject;
,我尝试使用
[NSDictionary dictionaryWithObjectsAndKeys:]
[NSDictionary dictionaryWithObjectsAndKeys:]
someEnumObject, @"enum",
我明白了
警告:语义问题:指针转换不兼容的整数,向"id"类型的参数发送枚举行为"
warning: Semantic Issue: Incompatible integer to pointer conversion sending 'enum behaviour' to parameter of type 'id'
推荐答案
使用以下内容将其保存到字典中,
Use the following to save it to dictionary,
[NSNumber numberWithInt:enumValue], @"enum",
您可以将其检索为
enumValue = [[dictionary valueForKey:@"enum"] intValue];
这篇关于将枚举值保存到字典中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文