swipe to delete cell swiftui code example
Example: swipe right to delete swiftui
struct SingleIsland {
let name: String
}
struct ContentView: View {
@State var islands = [
SingleIsland(name: "Wangerooge"),
SingleIsland(name: "Spiekeroog"),
SingleIsland(name: "Langeoog")
]
var body: some View {
List {
ForEach(islands.identified(by: \.name)) { island in
Text(island.name)
}.onDelete(perform: delete)
}
}
private func delete(with indexSet: IndexSet) {
indexSet.forEach ({ index in
islands.remove(at: index)
})
}
}