Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude a Realm model class

Tags:

ios

swift

realm

I have two Realm files configured in my app. I want to store my Log model to a separate file from the rest of my models. My problem is that I also see my Log model class in my default Realm file, which I don't want. How can I exclude a particular model class from a given Realm file?

I use the default configuration for my main Realm file, and I want to store the Log model only in another database file, but when I default.realm in the Realm Browser it also shows the Log model.

enter image description here

like image 916
SPatel Avatar asked Feb 05 '23 14:02

SPatel


1 Answers

You can explicitly list the classes a given Realm can store via the objectTypes property on Realm.Configuration:

let configA = Realm.Configuration(fileURL: realmFileURL,
                                  objectTypes: [Dog.self, Owner.self])
let realmA = Realm(configuration: configA)


let configB = Realm.Configuration(fileURL: otherRealmFileURL,
                                  objectTypes: [Log.self])
let realmB = Realm(configuration: configB)

realmA can only store instances of Dog and Owner, while realmB can only store instance of Log.

like image 147
bdash Avatar answered Feb 07 '23 18:02

bdash