
SwiftUI Cookbook
By :

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.
Let's create a SwiftUI app called AddContactsApp
, ensuring that the Use Core Data checkbox is checked, as shown in the following screenshot:
Figure 11.7 – Creating a SwiftUI app with Core Data
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: