Getting Started with SwiftData
During Apple’s World Wide Developer Conference in 2023, they introduced SwiftData, an all-new framework to save app data. Previously, developers had to use an editor to create data models, but SwiftData allows developers to describe data models and manipulate model instances using regular Swift code. Features such as relationship management, undo/redo support, iCloud synchronization, and more are provided automatically.
In this chapter, you’re going to modify the JRNL app that you completed in Chapter 16, Passing Data between View Controllers, to save journal entries using SwiftData. This means that when you add new journal entries to the app, they will reappear the next time the app is launched.
First, you’ll learn about SwiftData and its components. Next, you’ll modify the JournalEntry
class to make it compatible with SwiftData, and modify the JournalListViewController
class to work with the modified JournalEntry...