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 ✏️")
}
}