Reputation: 4946
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.
Upvotes: 5
Views: 1009
Reputation: 18308
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
.
Upvotes: 7
Reputation: 3085
You can override this method in unmanaged classes
public class Log: Real.Object .... {
...
...
public override static func shouldIncludeInDefaultSchema() -> Bool {
return false
}
}
you can now create your realm with the default settings
let realm = Realm()
Upvotes: 3