I am new to SwiftData and I'm trying to use the .onMove modifier to rearrange "ChecklistItems"
List {
ForEach(items) { item in
ChecklistItemsListRowView(item: item, checklist: checklist)
.onTapGesture {
item.completed.toggle()
save()
} // onTapGesture
}
.onDelete(perform: { indexes in
for index in indexes {
modelContext.delete(checklist.items[index])
} // *for*
}) // onDelete
.onMove { IndexSet, int in
// TODO: Rearrange Elements
} // onMove
} // LIST
This is my ChecklistItem class:
@Model
final class ChecklistItem {
@Attribute(.unique)
var creationDate: Date
var name: String
var priority: Int
var notes: String
var completed: Bool
var checklist: Checklist?
init(creationDate: Date, name: String, priority: Int, notes: String, completed: Bool) {
self.creationDate = creationDate
self.name = name
self.priority = priority
self.notes = notes
self.completed = completed
}
}
extension ChecklistItem {
@Transient
static var preview = ChecklistItem(creationDate: Date(), name: "Item", priority: 2, notes: "This is a note.", completed: true)
}