SwiftData DataService?

In the Menu app, a DataService was used to abstract data access, which seemed like a nice pattern. Now working on my actual app, I’ve started to use SwiftData. It looks like SwiftData expects some of its operations to happen inside of Views, so it seems like I’d be going against convention to try to move all the SwiftData access inside a service… and SwiftData itself is somewhat of a generic abstraction for data access, so is the general practice just to use SwiftData directly?

For a good introduction on SwiftData have a look at this 8 part series from Paul Hudson on how to set up a project using it. Surprisingly simple.

This is the first video in the series:

I just started my iOS development journey about six weeks ago, so I’m no expert, but I’ve been looking closely at SwiftData for my first app, and you are correct. Although it is possible to use SwiftData along with the DataService concept, you would be foregoing much of the simplicity offered by SwiftData which is clearly designed to operate within views as you already noted.