我正在尝试从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.
更多推荐
从领域删除模型
发布评论