如何添加枚举到领域模型? RLMObject? [英] How to add enums to realm model? RLMObject?

查看:510
本文介绍了如何添加枚举到领域模型? RLMObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的serviceModel.h

This is my serviceModel.h

typedef NS_ENUM(NSInteger, OKServiceType) {
    OKServiceTypePending = 0,
    OKServiceTypeAccepted ,
    OKServiceTypeStarted,
    OKServiceTypeCompleted,
    OKServiceTypeClosed,
    OKServiceTypeCancelled
};
@interface serviceModel : RLMObject
@property NSString *job_id;
@property NSString *job_service_id;
@property NSString *service_id;
@property NSString *vendor_id;
@property NSString *timeslot;
@property NSString *points;
@property OKServiceType *status;
@property NSString *service_name;
@property NSString *image_url;
@property NSString *vendor_name;
@property NSString *subservice_desc;
@property NSString *subservice_id;
@property NSString *display_datetime;
@property NSString *status_text;
@end

RLM_ARRAY_TYPE(serviceModel)

我知道我们可以将属性类型添加为这些。但是我无法找到正确的方法来添加枚举给我的模型,因为领域只收集所有的模型,所以它由于这个

I know we can add the property type as These. But I cann;t find the proper way to add the enum to my models as realm collects all models on start only so it do crash due to this

@property OKServiceType *status;

我正在崩溃作为


错误错误Domain = NSCocoaErrorDomain代码= 3010模拟器中不支持远程通知

Error Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator"

UserInfo = {NSLocalizedDescription =远程通知不是
支持在模拟器中} 2017-06-12 15:20:41.049 AppName [9974:157085]

UserInfo={NSLocalizedDescription=remote notifications are not supported in the simulator} 2017-06-12 15:20:41.049 AppName[9974:157085]

***由于未捕获的异常终止应用程序RLMException ,原因:'不能持久的属性'status'与不兼容的类型。添加到
ignoredPropertyNames:忽略方法'

*** Terminating app due to uncaught exception 'RLMException', reason: 'Can't persist property 'status' with incompatible type. Add to ignoredPropertyNames: method to ignore.'

任何帮助将不胜感激alot ..

Any Help would be appreciated alot..

推荐答案

也许您想将您的财产存储为 NSInteger ,这是一种受支持的类型,并创建方法返回您的整数值作为枚举类型为 OKServiceType

Maybe you want to store your property as an NSInteger which is a supported type and create a method which returns your integer value as an enum of type OKServiceType.

@property NSInteger statusInt;

- (OKServiceType)status {
    return (OKServiceType)statusInt
}

- (void)setStatus(OKServiceType)status {
    self.statusInt = status
}

这篇关于如何添加枚举到领域模型? RLMObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆