exclude a Realm model class

人盡茶涼 提交于 2019-12-04 13:24:05
bdash

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.

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()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!