What you’ll learn in this chapter:
- How to save data persistently using the CoreData framework
- How to get and set global system settings using environment keys
- Retrieving saved data using the @FetchRequest property wrapper
- Creating a List containing dynamic and static rows
- Crafting search experiences in SwiftUI
What we’ll create 🚀
In this chapter, we’ll create a To-Do app. By doing this, we will learn how to store data persistently using the CoreData framework. CoreData is a framework primarily used “to save your application’s permanent data for offline use“. We will learn how to integrate CoreData in SwiftUI applications to retrieve and save data.
Let’s take a look at how our app should look like. Our To-Do app contains one view listing the pending tasks and one row used to add a new task to this list.
Furthermore, our To-Do app should contain a view that lists all tasks that have already been completed and a search bar for quickly finding certain tasks.
We start by defining the data model which we will use for our to-do tasks. Then we design the interface to display the tasks. Finally, we will implement CoreData to store and retrieve tasks permanently.
But first, we have to set up our project. As always, we start by creating a new Xcode project.
At this point, make sure you check the “Use Core Data“ box. By doing so, we ensure that Xcode automatically creates and modifies the files we need for using the CoreData framework in SwiftUI.

Go ahead and create your project as usual.
6 replies on “Chapter 10: To-Do App – SwiftUI and CoreData”
Hi,
This looks to be out-of-date as when creating a new project and selecting Core Data, it looks different and my ContentView has a lot of what looks like Coredata code in it.
What should I do ?
Hi Craig, during the chapter we will delete the pre-generated CoreData code and create our own from scratch!
Hi,
Thanks managed to see that and all working fine..
However, how do I make the back ground colour ?
Hi, if you refer to the black color scheme: it’ simply the app running on dark mode. If you want to have a custom background color, the best way to achieve this is to use a ZStack containing a coloured Rectangle view covering the whole screen.
Hi, I have tried using ZStack and a Rectangle with nil width and nil height.. but no go.
My xcdatamodeld isn’t named ‘Shared’ it’s named for the app, To_Do.xcdatamodeld and the changed items don’t appear.