从领域删除模型

编程入门 行业动态 更新时间:2024-10-24 17:32:44
本文介绍了从领域删除模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从Realm中删除模型.我似乎有一种简单的方法可以在Java中使用

I am trying to remove a model from Realm. I appears there's a straightforward way to do it in Java with

realm.getSchema().remove(className)

除了从App中删除模型然后迁移数据或删除整个Realm文件之外,Swift 3中没有其他选项.

It doesn't appear there is an option in Swift 3 other than to remove the model from the App and then migrate the data, or delete the entire Realm file.

为澄清起见,当我打开Realm Browser时,我有三种模型

To clarify, when I open the Realm Browser I have three models

Dog 2 Person 4 Test 0

,我想通过代码删除Test模型.似乎也没有任何方法可以通过浏览器将其删除.

and I want to remove just the Test model via code. There doesn't appear to be any way to remove it via the Browser either.

也许我忽略了文档中的某些内容?

Perhaps I overlooked something in the docs?

推荐答案

不,您没有忽略文档中的任何内容.

No, you haven't overlooked anything in the docs.

在不触发迁移的情况下,不可能在Objective-C/Swift SDK中修改Realm文件的架构.在这种情况下,您可以使用 Migration.deleteData(forType:) 从领域删除对象架构.

It is not possible to modify the schema of a Realm file in the Objective-C/Swift SDKs without triggering a migration. In which case, you can use Migration.deleteData(forType:) to delete the object schema from the Realm.

此外,如果您想首先确保没有将Test添加到您的Realm文件中,则可以明确定义在您的Realm配置中.

Additionally, if you want to explicitly ensure that Test isn't added to your Realm file in the first place, you can explicitly define that in your Realm configuration.

更多推荐

从领域删除模型

本文发布于:2023-11-25 13:49:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   领域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!