我刚开始使用 Realm 数据库。我查看了 Realm 文档,发现了一个 RLMObject 类方法属性属性:
我不明白它在做什么。
你能解释一下我什么时候可以并且需要使用它吗?
谢谢你的帮助。
您可以在实体类中覆盖此方法,实体类继承自 RLMObject 来指定属性方面的附加属性,这些属性会影响数据库的架构和行为。目前,您唯一的选择是是否将属性编入索引。
假设您有一个像文档中那样的模型类:
@interface Dog : RLMObject
@property NSInteger age;
@property NSString *name;
@kết thúc
v0.91.0 及更高版本:
自0.91.0发布以来,就是easier to define indexed properties 。如果您希望为 tên
列建立索引,那么您可以通过覆盖此处的类方法来实现。
+ (NSArray *)indexedProperties {
return @[@"age", @"name"];
}
v0.91.0 之前:
在此版本之前,您可以指定索引列,如下所示:
+ (RLMPropertyAttributes)attributesForProperty:(NSString *)propertyName {
RLMPropertyAttributes attributes = [super attributesForProperty:propertyName];
if ([propertyName isEqualToString:@"name"]) {
attributes |= RLMPropertyAttributeIndexed;
}
return attributes;
}
Tôi là một lập trình viên xuất sắc, rất giỏi!