SwiftData and Database Manager Layer
Hello all,
I’m trying to better understand the different techniques people use to manage a SwiftData layer in a scalable application.
I understand that ModelContext is used to create, update, and delete SwiftData models, but I’m struggling to see how this approach scales cleanly beyond smaller applications. Passing a ModelContext from a SwiftUI View into a view model feels awkward. Also, the Query property wrapper is tightly coupled to the SwiftUI view layer.
I have a lot of questions about the intended architecture here. The overall approach feels very “Apple,” but I’m having trouble understanding why it is considered scalable as an application grows. In my own project, I’m ending up with far too much persistence logic inside my SwiftUI Views, and the code is becoming increasingly difficult to manage.
I’d love to have an open discussion about how others structure and manage their SwiftData layer in larger applications. I’m especially interested in approaches that keep SwiftUI views focused on presentation while still working naturally with SwiftData.
Hopefully, this can lead to a useful discussion that helps all of us write cleaner, more maintainable code.
Best,
S