.onDelete is working fine on the mac when swiping from right to left with magic mouse or trackpad.
But i prefer to use a context menu and add the delete function there.
var body: some View {
List {
ForEach(items) { item in
Text("Item at \(item.timestamp!, formatter: itemFormatter)")
.contextMenu(ContextMenu(menuItems: {
Button(action: {
viewContext.delete(item)
do {
try viewContext.save()
} catch {
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
}, label: {
Text("Delete")
})
}))
}
.onDelete(perform: deleteItems)
}
.toolbar {
#if os(iOS)
EditButton()
#endif
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: