|
I spent the better part of last year learning Swift by building the backend code for my app, but now I'm at the point where I need to start designing the interface, and I figured I would try to learn SwiftUI at the same time. However, I've gotten to the point in my learning journey where the "out of the box" solutions most examples in tutorials demonstrate aren't quite applicable to what I'm trying to do, but at the same time, I'm not yet expert enough to be able to understand what the more complicated examples I can examine in various open-source projects are doing. My backend builds a database of
I'm wrapping the My individual types are classes, so I know I need to wrap them using
I don't actually get any errors when |
|
I'm not sure if what you're doing is wrong, but the way I'd do it would be to have some object encapsulate the array. Something like:
This way, any code that updates the list of books (filtering it, adding new items, removing items) would call methods on the |
|
Okay. Thank you. I had considered using that approach for my individual classes, instead of having the classes themselves conform to Question: Right now I've got my database as a whole wrapped like this to use as an
Would it be better to instead make the arrays within the database
And then add the method you suggested for replacing the arrays? |
|
Good question, but unfortunately we're running right up against the limits of my experience. My gut tells me that this is one of those decisions that really comes down to how hard it will be to maintain/modify in the future. The one insight I might offer is that so far, I've had better luck in Swift with shallow data structures than with really deep ones. |
|
Okay, thank you. With my far from solid-grasp of how Right now, as shown above, I have my JSON database wrapped as an Part of me wants to think that would mean that whenever a book (or author, or series) is added or removed from one of those arrays in the database, or a particular record is edited (new title, new authors, whatever) then, with the way my data model is set up, that change would happen to the database, and therefore any view watching the published database as an And the other part of me thinks there's no way it can be that easy and that I probably need, like you recommended, a So it would look more like this:
Yeah. I have no idea if I'm oversimplifying or overcomplicating things. |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.