Skip to content

Instantly share code, notes, and snippets.

@nnzo
Created October 21, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnzo/23b594c42b323c76b245818bb7e89fe9 to your computer and use it in GitHub Desktop.
Save nnzo/23b594c42b323c76b245818bb7e89fe9 to your computer and use it in GitHub Desktop.
Swipe right to delete SwiftUI List
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)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment