SwiftUI crash on ondelete

i delete a record from the db, when querying again to refresh my list on the UI, it throws RLMException*', reason: ‘Object has been deleted or invalidated.’*

here is the link for the gist:



Just a guess.

That’s probably where the issue is. Its possible you’ve deleted the object from Realm, but that objects index still exists in the array, but is now pointing to a non-existent object.

Best bet is to use Realm constructs to store data you’re using - e.g. Realm Results type objects always reflect the state of the underlying data - if an object is removed from Realm, it’s also removed from Results so therefore views that are being updated won’t try to access a non-existant object.

Again, just a guess - without a minimal, verifiable example, it’s hard to say.

Hi Jay,

I updated the gist, i added this line of code

let _idx = expensesList.firstIndex { oldExp in
                            oldExp.uuid == expToDelete!.uuid
                        if let __idx = _idx {
                            expensesList.remove(at: __idx)

but i am having issue, i am keen to use @ObserverResults by due to my complex query it may not be suffice, i also updated the gist of the complete query (loadExpenses) result i expected. If i can use @ObserveResults to achieve that, then well and good, i just need some concrete examples


I already make it work using the @ObserveResults i already updated the my public gist so that other may refer to it in the future

…though all the business logic move it to UI and i think for now is ok as long as it is working :smile: