Created
October 21, 2020 20:50
-
-
Save nnzo/23b594c42b323c76b245818bb7e89fe9 to your computer and use it in GitHub Desktop.
Swipe right to delete SwiftUI List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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