I\'m experimenting with SwiftUI and would like to fetch an update from my REST API with a search string.
However, I\'m not sure how to bring the two components together
There is no need to get UIKit involved, you can declare a simple search bar like this:
struct SearchBar: View {
@State var searchString: String = ""
var body: some View {
HStack {
TextField("Start typing",
text: $searchString,
onCommit: { self.performSearch() })
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: { self.performSearch() }) {
Image(systemName: "magnifyingglass")
}
} .padding()
}
func performSearch() {
}
}
and then place the search logic inside performSearch().