我无法删除领域数据库中的对象:我有以下异常:
0x108196d6f: movq 0x202112(%rip), %rcx ; "exceptionWithName:reason:userInfo:"
0x108196d76: leaq 0x1e6d0b(%rip), %rdx ; @"RLMException"
0x108196d7d: leaq 0x1e71c4(%rip), %rbx ; @"Unable to delete an object not persisted in this Realm."
当我使用领域浏览器检查时,记录在数据库中!谁有同样的问题?
这是我的代码:
func deleteDatabase() {
let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
for result in deleteUoMArray {
var item = result as UoM
var uomObject = UnitOfMeasurement()
uomObject.guid = item.guid
uomObject.unitOfMeasurement = item.unitOfMeasurement
uomObject.selected = item.selected
uomObject.index = item.index
realm.deleteObject(uomObject)
}
realm.commitWriteTransaction()
}
答案 0 :(得分:1)
如果您的目标是删除数据库中的所有对象,正如deleteDatabase
函数的名称所暗示的那样,您只需要调用:
let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
realm.deleteAllObjects()
realm.commitWriteTransaction()
否则,如果deleteUoMArray
是要删除的Array
,RLMResults
或RLMArray
个对象,则可以致电realm.deleteObjects(deleteUoMArray)
。