|
Hi! I am currently solving the challenge for Day 61, so I'm adapting my previous work to support SwiftData. My problem is more on the design side than on the coding one. What I had previously done was to create a Now, I am finding it a bit hard to adapt this architecture to support SwiftData. What I initially tried (after of course adapting the So now the obvious solution would be to move the list of users and the download of the data to the I'll attach the original
|
|
I think you may want to use MVVM in this case. Similar to this post - https://www.hackingwithswift.com/quick-start/swiftdata/how-to-use-mvvm-to-separate-swiftdata-from-your-views |
|
@Obelix thanks for the detailed answer. Of course many of your observations are true for real projects and I simply did not consider them for this very quick challenge, but of course I know the importance of naming conventions and the convenience of separating the logic from the presentation code. My question was more on the "If this is possible, how do I do this?" side of things, meaning: I know it would be advisable not to introduce the "download" code in the View itself, but then I wouldn't know how to perform a SwiftData query inside a class. @ygeras suggests using MVVM, but Paul himself writes in the article that doing so with SwiftUI and SwiftData creates even bigger problems. So my question is, where to draw the line? Especially in small and personal projects like I intend to develop, is it better to divide data and layout code or to accept some coupling for the sake of simplicity? Or are there other solutions I'm not aware of? |
|
Paul doesn't say it creates more problems :) he says it is more work invovled, as indeed |
|
@ygeras yeah, I meant problems as in "things to be taken care of". I'm starting to see that using MVVM or not is quite the debate in the SwiftUI world. Anyway thanks, I'll now go back to the project and see what fits best. |
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.