Implementing SwiftData components
Now that you have used the JournalEntry class to create a JournalEntry model, you will create a singleton class that contains a ModelContainer object and a ModelContext instance. You will then add methods to manipulate instances of the JournalEntry model stored in ModelContext.
The term singleton means that there is only one instance of this class in your app.
Follow these steps:
- Right-click the
JRNLfolder in the Project navigator and choose New File from Template... from the pop-up menu. - iOS should already be selected. Choose Swift File and then click Next.
- Name this file
SharedData. Click Create. TheSharedDatafile appears in the Project navigator. Move the file so that it is under theSceneDelegatefile. - Add the following code after the
importstatement:import SwiftData
This lets you use the SwiftData framework.
- Add the following code after the
importstatements...