Crashing on swiftui ondelete

SwifUI view

List {
}.onDelete { offset in
transactionModel.deleteTransaction(expense: expensesList[offset.first!])


if let localRealm = realm {
  if let toDelete  = localRealm.object(ofType: ExpenseData.self, forPrimaryKey: expense.uuid) {
    try! localRealm.write {


RLMException', reason: 'Object has been deleted or invalidated.'



Some debugging may be in order. Add a breakpoint to your code and step through it line by line, inspecting the vars and code execution along the way. When you spot something unexpected, update your question with that info and also include the specific line that’s crashing.

Also, the code is a bit incomplete so we don’t really know what’s being called or in what order.

Thanks Jay, after further investigation, i just figure out the cause of the issue. The issue comes when i try to access the expense object after i deleted it. So I just assign the properties i needed before deleting the object. thanks

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.