Adding Core Data objects to a SwiftUI view
A store without any data 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 in a Core Data database.
Getting ready
Let's create a SwiftUI app called AddContactsApp
, ensuring that the Use Core Data checkbox is checked, as shown in the following screenshot:
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:
- The first thing we must do is create...