SwiftData will not refresh my view when I add or delete items!

Hey, I am following along with Chris’ iOS Databases course Module 3 Lesson 9 – Adding the stats and have encountered an issue.

That is when I add a new update to the project, edit or delete one, the stats do not change in the project detail view. I need to reload it (go back to the list view and back again) for the stats to update and in the project list view, I need to restart the app for the stats to change. Why is this, Chris dosen’t behave like this… And more importantly, how do I fix it?

I followed along with the lesson and spent hours trying to solve but to no avail. Please could someone offer me assistance? Thanks in advance for your kind support.

Because my code is quite long I have put it on Github, it is clearer there, plus you can clone it. Here is the link

In I realise fact a similar error happened when I followed the same course Module 1 lesson 5 when I learned about relationships in SwiftData – the family list updates when I added a new family to swift data but when I added a member to a specific family, I needed to reload that view to make the changes take effect. Chris did this by updating a State property to make the UI change. This is not applicable in this context though.


Hi Daniel,

Welcome to the community.

I’ve had a look at your code and I can’t find where the issue is.

I also note that your code is significantly different to that specified by Chris Ching. I would encourage you to ensure that the codebase is the same so that you get the project working as specified in the course and once that is fine you can go about refactoring your code to your personal preference. As it is, it makes it difficult to follow along and also makes it difficult for you to identify where the problem is by comparing your code to that of Chris Ching’s which is posted in the project resources and code dropBox folder for that course.

As an aside we discourage members of the community specifying their email address in place of their name in the user profile section and would appreciate you removing it.

Hey Chris, thanks for taking a look at my code and the tips. I’m very new to the community so I’m sorry about the confusion of my username as email address. I’ll try to figure out how to change that.