OGeek|极客世界-中国程序员成长平台

标题: ios - Realm :多个实例,每个实例都有自己的配置 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:55
标题: ios - Realm :多个实例,每个实例都有自己的配置

我的应用程序使用两个独立的 Realm 实例(第二个来自库)。

应用程序本身使用 Realm.Configuration.defaultConfuguration 并且库创建自己的配置 (Realm.Configuration(...))。

在运行时(使用 Realm Browser 检查后),我们看到两个实例(每个实例都存在于自己的文件中)包含来自两个 Realm 的模型。当然,这对迁移有影响。

我知道当两者使用相同的配置时,我们应该设置 configuration.objectTypes ,但我没想到每个实例都有自己的配置时这很重要。

两个不同的配置如何在它们之间共享任何数据?这似乎是 Realm 中的一个错误 - 或者我可能遗漏了什么。



Best Answer-推荐答案


解释是posted在 GitHub 上 Realm 的问题中。我在此处复制响应以供将来搜索:

By default objectTypes will include all RealmSwift.Object subclasses, regardless of where they are defined.

A library which uses Realm should override shouldIncludeInDefaultSchema() to exclude its types from the default objectTypes (i.e. add public override class func shouldIncludeInDefaultSchema() -> Bool { return false } to the class definitions) and then explicitly list the types it uses. This lets any applications using the library continue to simply use the automatic class discovery.

功劳归Thomas Goyne ( Realm 开发者)。

关于ios - Realm :多个实例,每个实例都有自己的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49507690/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4