Delete model from Realm

女生的网名这么多〃 提交于 2020-01-06 19:28:36

问题


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)

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.

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

Dog 2
Person 4
Test 0

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?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/40696035/delete-model-from-realm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!