Listから指定した行を削除するにはonDeleteを使います。
struct ContentView: View {
@State private var rows = ["Sato","Suzuki","Takahashi","Tanaka"]
var body: some View {
VStack{
List{
ForEach(rows,id:\.self){
row in
Text("\(row)")
}
.onDelete(perform:removeRows)
}
}
}
func removeRows(offsets: IndexSet){
rows.remove(atOffsets: offsets)
}
}
![](https://hackswifttech.com/wp-content/uploads/2020/11/スクリーンショット-2020-11-17-15.36.45-2-555x1024.png)
![](https://hackswifttech.com/wp-content/uploads/2020/11/スクリーンショット-2020-11-17-15.36.51-1-555x1024.png)
上記のコードではonDelete()をする際の処理を別メソッドとして定義した物を指定していますが、
下記のようにすることもできます
.onDelete(perform:{ offsets in
rows.remove(atOffsets: offsets)
})