TextField Auto Searching with Combine
Maps UIKit SwiftUI
To support search for our SwiftUI application, we'll go ahead and add a TextField component into our UI. With this integrated, we'll then need to hook it up with a Bindable string somewhere. To make our code super clean, we'll create another @Published property inside of our View Model class. Again, this layer is going to keep track of everything that our UI needs to render. Finally, we can add a custom listener to our @Published properties by invoking debounce and sink. This way we don't over aggressively perform searches.

Comments (1)
shivaskanthan
3 years ago
A better solution to at 5:42 will be to remove the HStack and add padding to the VStack instead like below: var body: some View { ZStack(alignment: .top) { MapViewContainer(annotations: viewModel.annotations) .edgesIgnoringSafeArea(.all) VStack(spacing: 12) { TextField("Search for something...", text: $searchQuery) .padding() .background(Color.white) if viewModel.isSearching { Text("Searching...") } }.padding() } }
HELP & SUPPORT