2016-06-28 47 views
1

关于创建相互继承的领域对象只是一个简单的问题。继承RLMObject

@interface BaseObject : RLMObject 
@property long commonProp1; 
@property long commonProp2; 
@property long commonProp3; 
@end 

@interface InheritingObject : BaseObject 
@property NSString *name; 
@end 

@interface SecondInheritingObject : BaseObject 
@property NSString *name2; 
@end 

因此,BaseObject有一些属性,每个InheritingObject继承。这两个继承类是我想要在数据库中出现的唯一类。

有没有什么好方法可以避免出现在Realm中的BaseObject?

回答

1

您可以覆盖BaseObject上的类方法+[RLMObject shouldIncludeInDefaultSchema]并返回false,而您需要再次覆盖所有子类中的相同方法以返回true,以便它们不会被继承的重写方法排除。

Realm's source

// Returns whether the class is included in the default set of classes persisted in a Realm. 

+ (BOOL)shouldIncludeInDefaultSchema;