Modifying the JournalListViewController class
Previously, when you added or removed journal entries from your app, the changes made would be gone when you stopped and ran the app again because the code in the JournalListViewController
class had no way to save app data to your device. You will add code to the JournalListViewController
class to save app data using SwiftData in this section.
You will update the viewDidLoad()
method to fetch all journal entries from device storage when you run the app, update the unwindNewEntrySave(segue:)
method to add a new journal entry to the ModelContext
instance, and update the tableView(_:commit:forRowAt:)
method to remove the specified journal entry from the ModelContext
instance. Follow these steps:
- Click the
JournalListViewController
file in the Project navigator and add a method to fetch all journal entries from device storage before the closing curly brace:func fetchJournalEntries() { journalEntries = SharedData...