从领域删除模型 [英] Delete model from Realm

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

问题描述

我正在尝试从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文件中,则可以明确定义

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.

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

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