In SwiftUI on iOS, Lists must be in "Edit Mode" in order for ".onMove" to work. For some reason ".onDelete" will work even when not in "Edit Mode". You can let the user specifically enter edit mode by embedding the List in a "NavigationView"
NavigationView{
List{
ForEach(names, id: \.self) {name in
Text(name)
}.onMove(perform: { indices, newOffset in
names.move(fromOffsets: indices, toOffset: newOffset)
})
}.navigationBarItems(trailing: EditButton())
}
Or you can always be in "Edit Mode" by setting the environment variable programmatically like this:
List{
ForEach(names, id: \.self) {name in
Text(name)
}.onMove(perform: { indices, newOffset in
names.move(fromOffsets: indices, toOffset: newOffset)
})
}.environment(\.editMode, Binding.constant(EditMode.active))
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: