Deleting Core Data objects from a SwiftUI view
How can you delete objects from a Core Data repository? Removing objects is almost as important as adding them. In this recipe, we'll learn how to integrate the Core Data delete options into a SwiftUI app.
Getting ready
Create a SwiftUI app called DeleteContacts
.
Before we start this recipe, complete Steps 1 to 7 of the Showing Core Data objects with @FetchRequest recipe. Then, you can complete this recipe.
How to do it…
We are going to reuse part of the code provided in the Showing Core Data objects with @FetchRequest recipe. Please refer to that recipe if you want to find out more.
Let's get started:
- In the
ContentView
struct, add the list of contacts via the@FetchRequest
property wrapper:struct ContentView: View { @FetchRequest( sortDescriptors: [ ...