1

i have different realm objects in different ViewControllers and from my settingViewController i'm deleting all the data of app (the realm stored objects ) its working fine but when i move back to those viewControllers i got this exception :

Terminating app due to uncaught exception 'RLMException', reason: 'Object has been deleted or invalidated.'
*** First throw call stack:
(0x180c0adb0 0x18026ff80 0x100a13e7c 0x1001bd54c 0x1001be77c 0x1860c288c 0x1860c2c3c 0x185eb78e8 0x185d775b4 0x185eb6d34 0x192375f40 0x185ef1c94 0x192375ccc 0x1001b97ac 0x1001bbe4c 0x1860bf030 0x1860bf198 0x1860ae298 0x1860c3c64 0x185e548c4 0x185d641e4 0x1836f698c 0x1836f15c8 0x1836f1488 0x1836f0ab8 0x1836f0818 0x1836e9ddc 0x180bc0728 0x180bbe4cc 0x180bbe8fc 0x180ae8c50 0x1823d0088 0x185dd2088 0x100121cc8 0x1806868b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

i know its happening because system (kernel , iOS) dont knows that i've deleted those Realms Objects and system is trying to use that data which is not exists anymore (Correct me if i'm wrong) , any one can guide me on how i can fix this problem ???

3
  • Deleting a Realm file while you're still accessing it will lead to bad things like this. I suggest you stop accessing the Realm prior to deleting the file.
    – jpsim
    Commented Aug 5, 2016 at 19:56
  • @jpsim thanks for responding man , can you elaborate me a bit how to do it ?
    – remy boys
    Commented Aug 5, 2016 at 20:53
  • To stop accessing a Realm, you'll need to deallocate all instances that are backed by data from that Realm. That means Realm, Object, Results, Lists, LinkingObjects, as well as stopping any notifications you have that could still be listening to changes. You'll likely need to read up on ARC and autoreleasepools to learn more about how to do this: developer.apple.com/library/ios/documentation/Swift/Conceptual/…
    – jpsim
    Commented Aug 5, 2016 at 21:36

1 Answer 1

2

I suggest you to make notification before deleting all your data to all view controllers, that manipulate with it:

  1. Push notification from your settingViewController before wipe
  2. Subscribe to this everywhere you need to clear objects.
  3. delete references
  4. perform clean in your settingViewController.

Or, other way - implement delegate pattern for your purpose. The idea is the same.

Hope this helps.

2
  • 1
    hey man thanks for responding , do you know any tutorial related to this ? about your first option , cause i got an idea what to do but no idea about how to do it
    – remy boys
    Commented Aug 5, 2016 at 20:43
  • @remyboys, i think realm.io/docs/swift/latest/#realm-notifications is what you are searching
    – Doro
    Commented Aug 5, 2016 at 21:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.