Reputation: 2916
Basically my problem is that I want to define a realm object (RealmSwift.Object
subclass) and I do not want it to appear in the Realm database, instruct Realm to skip this one.
For example:
I want to implement a synchronisation logic in a private pod with dynamic list of objects that are all subclassed from an object, called SyncableObject
.
I have two classes that I register into my sync module (ConcreteClassA
and ConcreteClassB
) like SyncModule.register([ConcreteClassA.self, ConcreteClassB.self])
.
Now Realm detects that I have 3 RealmSwift.Object
subclasses and creates 3 different tables.
I want a solution to instruct Realm, not to create the table for the SyncableObject
(intermediate object) class, like overriding a class function or something like that.
Upvotes: 1
Views: 603
Reputation: 2916
By upgrading the previous solutions, I figured that this will do the trick to not include the base object and do include the subclasses:
/**
Do not include SyncableObject into schema, only the subclasses
*/
public override class func shouldIncludeInDefaultSchema() -> Bool {
return SyncableObject.className() != self.className()
}
Upvotes: 1
Reputation: 4848
Here's the answer in Swift
:
override class func shouldIncludeInDefaultSchema() -> Bool {
return false
}
Upvotes: 0
Reputation: 14409
You'll want to override +[RLMObject shouldIncludeInDefaultSchema]
. From Realm's source:
// Returns whether the class is included in the default set of classes persisted in a Realm.
+ (BOOL)shouldIncludeInDefaultSchema;
Upvotes: 2