Swiftui MacOS App Example Project OnDelete func

Hello, i am very new with macos development and wanted to create a MacOS app with SwiftUI. I initiate a project with coredata checked and wanted to see how it behaves. So how do I delete this item? It has onDelete function but not functioning

Thanks

The onDelete(perform:) modifier should cause list rows to be deleted through a swipe action. Are you saying this isn't working?

If you are talking about removing items from SwiftUI lists, the modifier for Mac apps is .onDeleteCommand instead of .onDelete, which iOS apps use.

For anyone to provide more help, you have to provide the code to delete the item from Core Data and the SwiftUI code for deleting items.

The following article may help you:

https://www.swiftdevjournal.com/removing-items-from-swiftui-lists-in-mac-apps/

Update

I have just created a new macOS project with Core Data enabled and run the program without modifying the template code.

Even though the onDelete(perform:) modifier has been attached to the ForEach, the delete swipe action won't work as the List is in a sidebar-style state. If you change the list style to something different, like .inset, the swipe action will work.

You could use the onDeleteCommand(perform:) modifier where you can delete the currently selected item in the List when the delete key is pressed.

You could also add a contextMenu(menuItems:) modifier and add your own Button that deletes the selected item.

Swiftui MacOS App Example Project OnDelete func
 
 
Q