|
I'm a bit out of practice, but decided to come back here to learn how to use SwiftData. I completed the "Building a Complete Project" section of the new book, and made an attempt at the challenges at the end. I got it all to work as described in the challenges, but can't help feeling like the way that I did it is not the best way of solving the problem, so I just wanted to post here for advice on the final challenge.
So, I basically just added the extra menu in
Then, I modified the initializer for
Did I do this the right way more or less? Or is there a better way that my out of practice brain can't think of? |
|
It works? Ok then. More or less, it's the right way! However, I think @twoStraws was hinting you should try the techniques listed in this article. See -> Dynamically Changing a Predicate Instead of passing in a boolean that is evaluated in another struct, pass in a predicate representing the choice made in the other view. You're doing something similar with the sort descriptors in your code above. Can you do the same with the predicate? Try to make a choice, and form the predicate in one view, then pass the predicate to the next view to execute. |
|
So, for the sort, there was an initializer for The way that I did it, I basically just used these two variables and these two menus...
It seems like what you are telling me is that I should be using I've only seen |
|
I know that the link provided in the response above shows an example of how to use a dynamically changing sort, but can anyone provide an example of how to do the same with the predicate? That part is not clear to me. |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
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.