Search UI with Combine Throttling
Maps UIKit SwiftUI
Implementing search inside of an application is always pretty tricky when it comes detecting keystrokes. In today's lesson, I'll go through how to first build out the UI that contains our text field. Then we'll go over a brand new way of using Combine to delay keystroke change events.

Comments (5)
jsayer7
3 years ago
To resolve the warning "Result of call to 'sink(receiveValue:) is unused`, create a variable of type "AnyCancellable?" and change the combine throttling method to: self.cancellable = NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: searchTextField) .debounce(for: .milliseconds(500), scheduler: RunLoop.main) .sink { _ in self.performLocalSearch() } Assigning that function to the cancellable variable causes the memory to be automatically deinitialized when the view is destroyed.
rick27
3 years ago
Or just add _ = before (NotificationCenter.default)
Hua Wang
3 years ago
Brian, what is system requirement for the combine throttling? it doesn't perform the search and display the annotation after the i type in the search word in the textfield. I am running xcode 11.3 on MBP catalina 10.15.2.
Brian Voong
3 years ago
Brian Voong
3 years ago
Hua Wang
3 years ago
got it thanks!
frankusu
3 years ago
Hey Brain as always, brilliant ! What would happen if the user doesn't have iOS 13+ ? would the UI throttling crash the app?
Jp1478
3 years ago
i get this error once im done with the new school method to throttling Failed local search: Error Domain=MKErrorDomain Code=4 "(null)" UserInfo={MKErrorGEOError=-8}
johnkkk
2 years ago
The notificationCenter listener of textField is not working on latest Xcode. I downloaded the demo project and cannot work. The sink code block has never been called. No idea what's going on.
Brian Voong
2 years ago
HELP & SUPPORT