iphone - 将枚举值保存到字典中

标签 iphone objective-c ios nsdictionary

如何将枚举值保存到字典中?

当我尝试以下操作时

enum someEnum
{
    field0 = 0,
    field1 = 1,
    field2 = 2,
};

enum someEnum someEnumObject;

然后我尝试使用

将其保存到字典中

[NSDictionary dictionaryWithObjectsAndKeys:]

someEnumObject, @"enum", 

我明白了

warning: Semantic Issue: Incompatible integer to pointer conversion sending 'enum behaviour' to parameter of type 'id'

最佳答案

使用下面的方法将其保存到字典中,

[NSNumber numberWithInt:enumValue], @"enum",

你可以检索它,

enumValue = [[dictionary valueForKey:@"enum"] intValue];

关于iphone - 将枚举值保存到字典中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6663686/

相关文章:

iPhone sdk - 所有者姓名?

iphone - 如何复制 NSMutableAttributedString

ios - 我无法删除我注册的观察员

objective-c - 在 Swift 中使用 Objective-C 时,Xcode 无法识别 CGFloat/UIFont/CGSize

iOS 10 和权限本地化说明

iphone - 一般的 iPhone 粘贴板会包含多个项目吗?

ios - Swift 二维数组最小值

ios - AFNetworking 请求返回 nil

ios - 缺少 64 位支持和 Lipo 错误!!无法在 Xcode 6.3 中打开输入文件

iphone - 苹果是否会皱眉或不允许特定于设备的编码?