SwiftUI EditButton still not working

I have been developing a SwiftUI app for about a year now. From the early days the UI had EditButtons working OK. These stopped working when Xcode 12 came along. I reported this to the Feedback assistant, but have a had no reply. The issue is still there in the latest release candidate 12.2 beta 4. The code below is the test app I sent to Apple. It works if you remove .navigationViewStyle (in this test app, but not in my app). If anyone thinks I have made a mistake and that the issue is down to me, please let me know, otherwise if anyone from Apple is reading this please fix it. It seems rather fundamental to me.

Code Block swift
import SwiftUI
struct ContentView: View {
    @State private var myArray: [String] = ["One", "Two", "Three"]
    var body: some View {
        NavigationView {
            VStack {
                List {
                    ForEach(myArray, id: \.self) { item in
                        Text(item)
                    }
                    .onDelete { indexSet in
                        myArray.remove(atOffsets: indexSet)
                    }
                }
            }
            .navigationBarTitle("Navigation")
            .navigationBarItems(trailing: EditButton())
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}


Can you explain exactly what isn't working?

I tried your code on Xcode 12.1, and saw a working "Edit" button in the navigation bar.
When the edit button tapped it switches to 'Done', but the table doesn't change to display the delete buttons.

the table doesn't change to display the delete buttons

It does for me!
The delete also works.

Sorry, I know "it works for me!" may not be very helpful, but perhaps it suggests that the issue lies elsewhere?

What version of IOS are you using?
The problem is in IOS 14. It works fine in iOS 13.6.
Moving navigationViewStyle makes it work:
Edit now allows Edit of each cell with the red button on the left.
Same behavior on 12.1 and 11.6 on iOS 14, but was OK on iOS 13.

Code Block
import SwiftUI
struct ContentView: View {
@State private var myArray: [String] = ["One", "Two", "Three"]
var body: some View {
NavigationView {
VStack {
List {
ForEach(myArray, id: \.self) { item in
Text(item)
}
.onDelete { indexSet in
myArray.remove(atOffsets: indexSet)
}
}
}.navigationViewStyle(StackNavigationViewStyle()) // MOVED HERE
.navigationBarTitle("Navigation")
.navigationBarItems(trailing: EditButton())
} // MOVED UPWARD .navigationViewStyle(StackNavigationViewStyle())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

Doh! Thanks. They must have changed something because it was working fine for about a year!
I was wrong. Moving NavigationViewStyle is a red herring. If you remove it altogether it works. It has no effect in the new position (try changing it to .navigationViewStyle(DoubleColumnNavigationViewStyle()) and you'll see that on iPad). I have managed to get it working in the main view of my App (not this test app), but don't understand why. There seems to be some interaction with .sheet going on. I think it's actually some sort of threading/timing error in SwiftUI. Like I said before, it was working fine in iOS 13.6, so they have clearly screwed something up. Apple, as is often the case, seem totally uninterested.
I have the exact same issue using Xcode 12.2 and iOS 14.2 using almost the exact same code at the start of this thread but my list is building from a @FetchRequest. It works correctly every now and then but seems to only work 100% of the time after I've added a new entity into my CoreDate. The issue is exactly how Easiwriter says: "When the edit button tapped it switches to 'Done', but the table doesn't change to display the delete buttons". Swipe to delete works fine.

My code isn't using .navigationViewStyle

I'd love to know a solution.
@Easiwriter So you made it work. Great.

Don't forget to close the thread by marking the provided correct answer.
SwiftUI EditButton still not working
 
 
Q