When my user logs out, I clear my realm with realm.deleteAll(). After this, I get a lot of notifications resulting in reads from Results objects, which results in an exception realm::Results::InvalidatedException, "RLMResults has been invalidated". I can't find a way to
check a
Resultsobject for invalidation directly;check a
Results'realmobject for invalidation; orget the
ListtheResultsis derived from in order to check its invalidation state.
I can't think of anything else to look for. If there's a better way to clear the database that won't result in exceptions all over the place, I'd be happy to hear about that too.
Additional information: the exception is thrown even when calling count on a Results object, not just accessing its objects.
You can check if the first object exist, from Swift Docs:
From Realm Documentation for Java (could not find the same wording in Swift Docs):
Long story short, check if the first object exist of or try to count the elements.
Sources:
Java - Class RealmResults,
Swift - Results Class Reference
EDIT: Here is a code sample, it is taken from Realm example and modified to my needs, they use notification token to detect if the array is empty
I also clear the table using deleteAll():