本文介绍了带有NSnumber的枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何创建包含NSNumber的枚举?
i在我的应用程序中具有coredata持久性,一个实体的状态属性在coredata中声明为Integer 16,这意味着它是一个NSNumber

How do I create an enum that contains NSNumber ??i have a coredata persistence in my application, an entity has a status property declared as Integer 16 in coredata that means it is an NSNumber

能够声明我的枚举以便包含NSNumber而不是int,这样我就可以使用它们而不必写这个糟糕的事情

I would love to be able to declare my enum in order to contain NSNumber and not int so i can use them without having to write this awful thing

enum {
  ERROR,
  INCOMPLETE,
  OK
} EventStatus;

[myObjectOnCoredata setStatus: [[NSNumber alloc] initWithInt:INCOMPLETE]];

而仅仅是:

[muObjectOnCoredata setStatus: INCOMPLETE];

我认为应该可以,因为我可以将枚举声明为NSInteger,但这仍然不是很好对我来说

I think it shoul be possible since I can declare the enum as NSInteger, but it still is not good for me

感谢任何帮助

推荐答案

在托管对象为 statusNumber

然后

@dynamic statusNumber


- (void)setStatus:(EventStatus)status {
    self.statusNumber = [[NSNumber alloc] initWithInt:status]];
}

- (EventStatus)status {
    return [self.statusNumber intValue];
}

只需将转换隐藏到实现中即可。

Just hide the conversions into your implementation.

这篇关于带有NSnumber的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 15:37