ios – Crash when making an attempt to scroll utilizing ScrollViewReader in a SwiftUI Checklist

[ad_1]

I’m making an attempt to scroll to a newly appended view in a SwiftUI Checklist utilizing ScrollViewReader however maintain crashing with EXC_BAD_INSTRUCTION in scrollTo(_:) after including a couple of gadgets. I’m utilizing Xcode 14.0.1 and iOS 16.0 simulator.

Here’s a minimal demo that reveals the difficulty:

struct ContentView: View {

    @State var gadgets = [Item]()
    @State var scrollItem: UUID? = nil
    
    var physique: some View {
        NavigationView {
            ScrollViewReader { proxy in
                Checklist {
                    ForEach(gadgets) { merchandise in
                        Textual content(merchandise.id.uuidString)
                            .id(merchandise.id)
                    }
                }
                .listStyle(.inset)
                .onChange(of: scrollItem) { newValue in
                    proxy.scrollTo(newValue)
                }
            }
            .navigationTitle("Checklist Demo")
            .toolbar {
                Button("Add") {
                    addItem()
                }
            }
        }
    }

    func addItem() {
        gadgets.append(Merchandise())
        scrollItem = gadgets.final?.id
    }
}

struct Merchandise: Identifiable {
    let id = UUID()
}

I can get previous the difficulty utilizing a ScrollView as an alternative of a Checklist, however I wish to use the native swipe-to-delete performance in the actual challenge.

[ad_2]

Leave a Reply