在 Realm 中从 child class 调用 [super defaultPropertyValues] 是一个好习惯吗?

Is it a good practice to call [super defaultPropertyValues] from child class in Realm?

我的问题不仅涉及 + (NSDictionary *)defaultPropertyValues 方法,还涉及 + (NSArray *)ignoredProperties+ (NSArray *)indexedProperties 等其他方法

例如:

//.h - file
@interface A : RLMObject
@property NSString propertyA;
@end

//.m - file 
@implementation A
+ (NSDictionary *)defaultPropertyValues {
      return @{@"propertyA":@""};
}
@end

比我定义的class B继承了A的形式

//.h - file
@interface B : A
@property NSString propertyB;
@end

//.m - file 
@implementation B
+ (NSDictionary *)defaultPropertyValues {
   NSMutableDictionary *defaultValues = [[super  defaultPropertyValues]mutableCopy];
  [defaultValues setObject:@"" forKey:@"propertyB"];
  return defaultValues;
@end    

(免责声明:我为 Realm 工作。)

如果您只是简单地子classing RLMObject,则没有必要在这些 class 方法上调用 super

话虽这么说,在你的情况下,你随后要对 RLMObject 的子 class 进行子class,那么是的,这绝对是一个很好的方法确保您没有破坏父 classes 的功能。

我个人认为这是很好的做法,因为这意味着您不会在这些方法中创建冗余信息(即,如果您在 class A、class B 就可以了)。 :)