onMove

Im new to swiftui and I just tried implementing onMove into my project but for some reason it not only lags a lot when I attempt to move the item but the item then goes back to its original place any idea why?(Also my ItemModel does conform to Identifiable so it does have an id)

import SwiftUI

struct ListView: View { @State private var itemModel : [ItemModel] = [ ItemModel(title: "This Is Item 1", isCompleted: false), ItemModel(title: "This Is Item 2", isCompleted: true), ItemModel(title: "This Is Item 3", isCompleted: false) ]

var body: some View {
    VStack(spacing: 20) {
        List{
        ForEach(itemModel) { items in
            Text(items.title)
            }
        .onDelete(perform: { indexSet in
            itemModel.remove(atOffsets: indexSet)
        })
        .onMove(perform: { indices, newOffset in
            itemModel.move(fromOffsets: indices, toOffset: newOffset)
        })
        }
        .listStyle(.plain)
        .toolbar {
            ToolbarItem(placement: .topBarLeading){
                EditButton()
            }
            
            ToolbarItem(placement: .topBarTrailing) {
                NavigationLink(destination: AddItemsView(), label: {
                    Text("add")
                })
            }
        }
        
        Spacer()
    }
    .navigationTitle("To Do List ✏️")
    
}

}

Hi @theonevk ,

I tested this on an iPad and iPhone simulator running iOS 18 using Xcode 16 beta. I could not reproduce the behavior

Are you running this on device? If so, which device, which iOS or macOS version, and which Xcode version are you on?

onMove
 
 
Q