Coder Social home page Coder Social logo

swiftui-coredata-crash's Introduction

When using swipeActions modifier on a List row view, as soon as we try to use a button with destructive role as a custom delete action, the app crashes. Crash only occurs if we try to delete the last element in the list and only if the row view holds a reference to the Core Data managed object via @ObservedObject property wrapper.

Possible workaround right now are to not use swipeActions and instead use onDelete from ForEach, which loses customization, such as additional confirmation dialogs etc. Or removing the role from a button as seen with the Delete button thats tinted with green color.

Another SO thread about this issue - https://stackoverflow.com/questions/75352046/swiftui-app-crashes-when-using-destructive-button-in-swipeactions-and-obser

  • A step-by-step set of instructions to reproduce the problem (if possible)
  1. Clone the repository and try running the project in either preview, simulator or on device.
  2. Go to the list view and use swipeAction to delete the LAST item in the list.
    • the crashing button is the one with an X symbol as icon. All other swipe buttons are there to showcase other solutions, which do not crash the app.
  • What results you expected

Last list item is deleted from the list and core data context. Application does not crash

  • What results you actually saw

App crashes after deleting the last item in a list

Error: Thread 1: "attempt to delete item 2 from section 0 which only contains 2 items before the update“

  • The version of Xcode you are using

Version 15.1 (15C65)

swiftui-coredata-crash's People

Contributors

berhtulf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.