exclude model class Realm

I have two Realm files configured in my application. I want to save my model Log

to a separate file from the rest of my models. My problem is that I can also see my model class Log

in my default Realm file, which I don't want. How can I exclude a specific model class from a given Realm file?

I am using the default config for my main Realm file and I only want to save the model Log

in another database file, but when I am default.realm

in the Realm browser it also shows the model Log

.

enter image description here

+3


source to share


2 answers


You can explicitly list the classes for a given scope can store through the property on : objectTypes

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 Dog

and Owner

, whereas realmB

can only store instances Log

.

+5


source


You can override this method in unmanaged classes

public class Log: Real.Object .... {
    ...
    ...
    public  override static func shouldIncludeInDefaultSchema() -> Bool {
        return false
    }
}

      



Now you can create your own area with default settings

   let realm = Realm()

      

+1


source







All Articles