Summary
In this chapter, you modified the JRNL app that you completed in Chapter 16, Passing Data between View Controllers, to use SwiftData to save journal entries to your device storage, so that any changes you make will still be there when you next launch the app. First, you learned about SwiftData and its different components. Next, you modified the JournalEntry
class to make it work with SwiftData and modified your JournalListViewController
class to work with the modified JournalEntry
class. After that, you added code that allowed you to fetch, add, and delete journal entries from a SwiftData model container, and finally, you modified the JournalViewController
class so it can read, save, and delete stored journal entries.
You now have a basic understanding of how SwiftData works, and you will now be able to write your own apps that use SwiftData to save app data. Great job!
In the next chapter, you’ll learn about the latest developments in SwiftUI.