|
I have a question about SwiftData and the implementation presented by Paul in the iTour app @ SwiftData by Example I think I have understood this so far, but would now like to extend the app so that the user has the option of selecting, e.g. via a picker, in which element he wants to search. In the implementation shown by Paul, the searchString is passed and this is then processed in the init method:
It searches in "name". How would I have to extend the init method so that I could search in "name" or "details", for example? The call is made in the ContentView:
In the ContentView, I would then create a second picker in the ".toolbar" where the user can choose between "name" and "details". Something like this:
Can anyone help me with the question of how I need to pass "searchColumn" to DestinationListingView and then process it correctly in the init method to apply the saerchString to different elements. |
|
It is as easy as adding OR to your predicate as follows:
And in this case you don't need to choose where to look for your search, it will seach in both places. I suppose from user experience side it is more friendly way to look for things than switching in every search... |
|
OK, thanks for the answer, that would be one possible way. However, I would then not have the option of selecting which field I want to search in, or have I overlooked something in the answer? |
|
Sorry but maybe I got something wrong? My logic is following. I use |
|
I understand, that use cases maybe different. If you still need to use it for whatever reason you can do as follows (maybe to change it to enum later):
|
|
Ah, thank you - once again I was thinking too complicated - how annoying. I tried to incorporate searchColumn directly into "$0..." somehow - stupid of me. I didn't think of the simple possibility of an if statement with searchColumn. Thanks again, also for the hint with the OR, which as you correctly wrote is also logical for the iTour app. I have described my problem using the iTour app, but I would like to use it in my app, and I would like to search specifically in different areas of the list. I wish you a few relaxing holidays, a Merry Christmas and a Happy New Year :-) |
|
We all tend to make things a bit more complicated at times :) and that's ok. Thank you so much, have a nice holiday too @ralfb1105 , Merry Christmas and a Happy New Year!!! |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
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.