Reorder multiple items in list - SwiftUI

Hello,

I am unable to move multiple rows in a list, it only allows for one at a time. However, I am able to select multiple rows.

Here is my code:

import SwiftUI

struct ContentView: View {
    
    @State var items = ["Test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6"]
    @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: { indices, newOffset in
                    withAnimation {
                        self.items.move(fromOffsets: indices, toOffset: newOffset)
                    }
                })
            }
            
#if os(iOS)
            .navigationBarItems(trailing: EditButton())
#endif
            
        }
        .padding()
    }
}

I need all the selected rows to move when dragged.

Any help would be greatly appreciated, I have tried, and can not find any way to do it.

Thanks, Dev_101

Answered by Claude31 in 783951022

I tested in MacOS (destination is MacOS only), it works perfectly.

I observe the same.

But apparently, some have it working: https://developer.apple.com/forums/thread/656002

Hi @Dev_Pro , this is not possible in iOS, please file a feedback report at https://feedbackassistant.apple.com -> Developer Technologies and SDKs -> iOS -> SwiftUI

@sha921 I know it is not possible in iOS, but I would like it for macOS, which I know is possible because a bunch of apps support that feature.

Alternatively, If I can have to variables that record the selection: one being a Set and other a String, that would be perfect.

Accepted Answer

I tested in MacOS (destination is MacOS only), it works perfectly.

Reorder multiple items in list - SwiftUI
 
 
Q