【发布时间】:2015-02-16 11:23:35
【问题描述】:
我对使用领域数据库很陌生。我查看了领域文档,发现了一个 RLMObject 类方法
attributesForProperty:
我不明白它在做什么。
你能解释我什么时候可以和需要使用它吗?
感谢您的帮助。
【问题讨论】:
我对使用领域数据库很陌生。我查看了领域文档,发现了一个 RLMObject 类方法
attributesForProperty:
我不明白它在做什么。
你能解释我什么时候可以和需要使用它吗?
感谢您的帮助。
【问题讨论】:
您可以在继承自RLMObject 的实体类中覆盖此方法,以指定属性方面的附加属性,这些属性会影响数据库的架构和行为。目前,您唯一的选择是是否将某个属性编入索引。
假设您有一个像文档中那样的模型类:
@interface Dog : RLMObject
@property NSInteger age;
@property NSString *name;
@end
0.91.0自发布以来就是easier to define indexed properties。如果你想让name 列被索引,那么你可以通过覆盖类方法来做到这一点。
+ (NSArray *)indexedProperties {
return @[@"age", @"name"];
}
在此版本之前,您可以指定索引列,如下所示:
+ (RLMPropertyAttributes)attributesForProperty:(NSString *)propertyName {
RLMPropertyAttributes attributes = [super attributesForProperty:propertyName];
if ([propertyName isEqualToString:@"name"]) {
attributes |= RLMPropertyAttributeIndexed;
}
return attributes;
}
【讨论】:
return @[@"age", @"name"];