排除Realm模型类 [英] exclude a Realm model class

查看:80
本文介绍了排除Realm模型类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中配置了两个Realm文件.我想将我的Log模型与其他模型存储到单独的文件中.我的问题是,我还在默认的Realm文件中看到了我的Log模型类,这是我不想要的.如何从给定的Realm文件中排除特定的模型类?

我为我的主要Realm文件使用默认配置,并且我只想将Log模型存储在另一个数据库文件中,但是当我default.realm在领域浏览器中时,它也会显示Log模型./p>

解决方案

您可以通过 解决方案

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.

这篇关于排除Realm模型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆