How can I enable multi-select and then move / reorder selected items in a List with ForEach (in SwiftUI)?
I tried the following code. On Mac it works fine - it allows me to select multiple items, and then drag them all together to another place in the list. On iOS it allows me to move individual items with drag-and-drop, and allows me to enter Edit mode to select multiple items but when I try to move the selected items with drag-and-drop, they can be dragged but they can't be dropped elsewhere in the list:
struct ExampleListView: View {
@State var items = ["Dave", "Tom", "Jeremy", "Luke", "Phil"]
@State var selectedItems: Set<String> = .init()
var body: some View {
NavigationView {
List(selection: $selectedItems) {
ForEach(items, id: \.self) { item in
Text(item).tag(item)
}.onMove(perform: move)
}
.navigationBarItems(trailing: EditButton())
}
}
func move(from source: IndexSet, to destination: Int) {
items.move(fromOffsets: source, toOffset: destination)
}
}
Edit - This code (which uses List only and doesn't use ForEach) has the same issue:
struct ExampleListView: View {
@State var items = ["Dave", "Tom", "Jeremy", "Luke", "Phil"]
@State var selectedItems: Set<String> = .init()
var body: some View {
NavigationView {
List($items, id: \.self, editActions: .all, selection: $selectedItems) { $item in
Text(item).tag(item)
}
.navigationBarItems(trailing: EditButton())
}
}
func move(from source: IndexSet, to destination: Int) {
items.move(fromOffsets: source, toOffset: destination)
}
}

One way to achieve this is to handle the drag-and-drop interactions manually. Here's how you can modify your code to enable multi-item drag-and-drop on both macOS and iOS