We now have a bit of test coverage on our feature using our powerful inline snapshot testing tools. It’s forcing us to assert on how data is fetched from our database, including the manner it is sorted. We even get test coverage on how our feature deletes some records from the database directly, and then that causes the state in our model to update. And it’s pretty incredible to see how easy it is to write tests on complex data types using these tools, and we will see that it will continue to pay dividends over and over in this series.
OK, we now know how to query for data in our feature to render all of our reminders lists. And we know how to delete a list when the user taps a “Delete” button. And we’ve even got some test coverage on the feature.
Let’s now move on to a more complex aspect of this app. Right now we are just showing the names of the reminders lists in the UI, but the real Reminders app also shows the number of uncompleted reminders for each list. We need to somehow query for not only the list of reminders, sorted by title, as we currently are, but also compute the number of reminders in each list.
And this is the kinda of thing that SQL excels at, and sadly SwiftData is not currently capable of performing. In order to execute this kind of query on Apple platforms you have to dip into CoreData APIs, which are cumbersome and not safe at all to use.
So let’s see what it takes to update our query to be more powerful.