- 아래 모디파이어들을 이용하려면 List가 아닌 ForEach를 사용해야 한다.
- 또한 표시되는 데이터를 State 변수화해야한다.
onDelete

struct EditMode: View {
@State private var items = AppleProduct.sampleList
var body: some View {
VStack {
List {
ForEach(items) { item in
Text(item.name)
}
.onDelete { rows in
items.remove(atOffsets: rows)
}
}
}
}
}
onMove
struct EditMode: View {
@State private var items = AppleProduct.sampleList
var body: some View {
VStack {
List {
ForEach(items) { item in
Text(item.name)
}
.onMove(perform: move)
.onDelete { rows in
items.remove(atOffsets: rows)
}
}
}
.toolbar {
EditButton()
}
}
func move(from: IndexSet, to: Int) {
items.move(fromOffsets: from, toOffset: to)
}
}