从Realm 0.95.3升级到Realm 0.96.3
RLMObjectStore.mm:106内的应用程序错误
引发错误,说明属性已成为可选属性
(lldb) po objectSchema
DTFLogMessage {
id {
type = string;
objectClassName = (null);
indexed = YES;
isPrimary = YES;
optional = YES;
}
creationDate {
type = date;
objectClassName = (null);
indexed = NO;
isPrimary = NO;
optional = YES;
}
message {
type = string;
objectClassName = (null);
indexed = NO;
isPrimary = NO;
optional = YES;
}
fileinfo {
type = string;
objectClassName = (null);
indexed = NO;
isPrimary = NO;
optional = YES;
}
type {
type = int;
objectClassName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}
}
如何使这些不再可选我在文档中没有看到有关如何执行此操作的任何内容。模型配置如下:
#import <Realm/RLMObject.h>
@interface DTFLogMessage : RLMObject
@property NSString *id;
@property NSDate *creationDate;
@property NSString *message;
@property NSString *fileinfo;
@property NSInteger type;
@end
RLM_ARRAY_TYPE(DTFLogMessage)
.m文件如下。
#import "DTFLogMessage.h"
@implementation DTFLogMessage
+ (NSString*)primaryKey
{
return @"id";
}
@end
答案 0 :(得分:1)
Realm的Optional Properties上的Objective-C文档解释了如何执行此操作:
默认情况下,
NSString *
,NSData *
和NSDate *
属性允许您将它们设置为nil。如果要要求存在值,可以覆盖RLMObject子类上的+requiredProperties
方法。例如,使用以下模型定义,尝试将人名设置为nil将引发异常,但允许将其生日设置为nil:
@interface Person : RLMObject
@property NSString *name;
@property NSDate *birthday;
@end
@implementation Person
+ (NSArray *)requiredProperties {
return @[@"name"];
}
@end