Kádi Kádi - 7 months ago 22
Swift Question

Do not map Realm object into Realm table

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.

Answer

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;
Comments