WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Flashzilla onDelete glitching

Forums > 100 Days of SwiftUI

Anyone else discovered that the onDelete gesture in EditScreen is really hard to perform, since the system tends to cancel it if you're not doing it super fast? Seems to happen in the sample solution as well, so I doubt it's a mistake on my part.

To debug, I tried to instantiate EditCards directly from FlashzillaApp and that way it worked perfectly. So maybe being presented in a .sheet is the issue? Are there any known workarounds for that?

(Xcode 13.2, iOS 15.2 device and simulator)


I have found that if the iPhone has the notch on the right (and charge port on left) then the delete does work properly, however if you flip the phone around with notch on the left then it works fine, so nothing wrong with code just a iOS bug. One for file a feedback.

(Tested on real iPhone 13 Pro Max)


I've had a bit more time for debugging today. It's all the fault of ContentView's timer!

To resolve this, first make the timer a @State like this:

@State var timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

Then add the cancellation of the timer to the +-Button that sets the variable for the EditScreen:

showingEditScreen = true

Finally, create a new timer at the end of resetCards():

timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

Now swiping to delete a Card on EditCards should work smoothly.


Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.