|
I've copied Paul's demo code here: https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-modifiers-for-a-uiviewrepresentable-struct into a new project. I've added Text(text) to the VStack just below the button, but it doesn't update when I type. How do I get the typed search string out of the SearchBar? Jeremy |
|
|
|
That's what I thought - so shouldn't this work (with the rest of Paul's code at the top)?
|
|
Try replacing the declaration with
You will see that the
Try using the
This will update each time
The UIView defines the
|
|
Greenamber, I'm obviously missing something essential. To be useful, it must be possible to get the typed text somehow. How can this be done, if not by using the text binding passed to SearchField? |
|
The situation is, as I said earlier, What was needed is a coordinator, where the text is updated, and using that coordinator in a delegate to the searchBar (UISearchBar()). Without the So there is a new class, using the makeCoordinator() function and assigning the context coordinator to the searchBar delegate. A new class.
The coordinator set up to use the
Set up the searchBar delegate.
I have added a list of fruit, as an example, to use for the search. Here is the whole main code.
|
|
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.