Adding Core Data objects from a SwiftUI view
A store without any data in it is useless. In this recipe, we will learn how easy it is to implement a function that will add data to Core Data in SwiftUI.
In this recipe, we are going to implement a simple Contact app where we can add storable contact profiles to a Core Data database.
Getting ready
Create a SwiftUI app called AddContacts
.
Before we start this recipe, complete Steps 1 to 4 of the Showing Core Data objects with @FetchRequest recipe. Then, you can complete this recipe.
How to do it…
Besides adding profiles, we must present our list of already saved contacts. For this, we are going to reuse some of the code from the Showing Core Data objects with @FetchRequest recipe.
To add a profile, we are going to implement a simple modal view with three text fields: two for the full name and one for the phone number. Let's get started:
- Let's look at the code for visualizing the contacts. Create...