5

I have used the realm in one of my projects and added Firebase to identify the crashes. Now, in one of the crash, I am getting following error in Firebase but did not get more details.

"Adding a deleted or invalidated object to a Realm is not permitted"

I have used below code everywhere, where I am trying to delete the object from the realm.

let realm = try! Realm()
do {
    try realm.write {
        realm.delete(object)
    }
} catch let error as NSError {
    // handle error
    Crashlytics.sharedInstance().setObjectValue(error.localizedDescription, forKey: "key")
}

Am I missing anything?

Thank you for your help

Anand
  • 1,820
  • 2
  • 18
  • 25
Vandit Mehta
  • 2,572
  • 26
  • 41
  • 1
    Possible duplicate of [Realm object has been deleted or invalidated](https://stackoverflow.com/questions/31852782/realm-object-has-been-deleted-or-invalidated) – Anand Apr 17 '19 at 11:30
  • @Anand, I have tried everything from that link... – Vandit Mehta Apr 17 '19 at 13:03
  • Don't try to re-add a managed RealmObject that you had previously deleted??? I would think the error message is quite clear. – EpicPandaForce Apr 17 '19 at 13:42
  • @EpicPandaForce, not re-adding anywhere. – Vandit Mehta Apr 18 '19 at 04:59
  • Clearly you are, that is why you are getting the error message ;) – EpicPandaForce Apr 18 '19 at 08:37
  • There's really no way to assist with this issue as we don't know what object is or what happened to it before this code runs. Probably should be closed unless the question is updated with a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Edit the question and we can take a look. – Jay Apr 20 '19 at 13:09

0 Answers0