Unable to delete an object in a realm database

I’m unable to delete an object in a realm database: I have following exception:

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."

The record is in the database when I check with realm browser!!! Who had the same problem?

  • Appium Instruments crashed on startup
  • Class are being linked more than once in target
  • Reloading an SKScene or View to remove iAd after In App Purchase
  • NSDate detection with NSDataDetector
  • Uploading an image from iOS to PHP
  • Upload video on youtube from iphone app
  • this is my code:

    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()
    }
    

    Solutions Collect From Internet About “Unable to delete an object in a realm database”

    If your goal is to delete all objects in the database, as the name of the deleteDatabase function would imply, all you need to do is call:

    let realm = RLMRealm.defaultRealm()
    realm.beginWriteTransaction()
    realm.deleteAllObjects()
    realm.commitWriteTransaction()
    

    Otherwise, if deleteUoMArray is an Array, RLMResults, or RLMArray of objects to delete, you can call realm.deleteObjects(deleteUoMArray).