List edit mode ios 14

On a simulator I'm trying to add editMode to a list and it looks like it is not working.
Code Block      
@State private var editMode = EditMode.active
             
List {
ForEach (array) {
product in Text("\(product.quantity) x \(product.name)")
  }
}.frame(maxHeight: geometry.size.height * 0.25)
.environment(\.editMode, $editMode)

Am I doing something wrong or is this a bug (or maybe not available) on ios 14?

Accepted Reply

You will need to add actions to each row in the list. Tapping on the edit button will do nothing to the rows.

To add delete and move actions:

Code Block Swift
List {
ForEach(array, id: \.self) { product in
Text("\(product.quantity) x \(product.name)")
// delete action
.onDelete { indexSet in
array.remove(atOffsets: indexSet)
}
// move action
.onMove { indexSet, newOffset in
array.move(fromOffsets: indexSet, toOffset: newOffset)
}
}
}


Replies

You will need to add actions to each row in the list. Tapping on the edit button will do nothing to the rows.

To add delete and move actions:

Code Block Swift
List {
ForEach(array, id: \.self) { product in
Text("\(product.quantity) x \(product.name)")
// delete action
.onDelete { indexSet in
array.remove(atOffsets: indexSet)
}
// move action
.onMove { indexSet, newOffset in
array.move(fromOffsets: indexSet, toOffset: newOffset)
}
}
}