Apologies
You must be signed in to watch this lesson.
Combine Search Bug Fixes
Maps UIKit SwiftUI
One quick issue I noticed since updating to Xcode 11.3 is that our search is no longer working. The main reason for this is that our search throttling code is not properly keeping track of references to our listeners. We'll fix this right away otherwise our app no longer works.

Comments (2)
David Guarino
4 years ago
Hey Brian, when searching for a place... results do not show when calling below function. I did some breakpoints, print statements and found out that "listener.cancel" is not executing. I changed "AnyCancellable!" back to "Any!" and took out "listener.cancel" and the search results work. However now I have the retain cycle we were trying to eliminate in the 1st place. Can you find out why this isn't working? var listener : AnyCancellable! fileprivate func setupSearchListener() { // search throttling listener = NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: searchField).debounce(for: .milliseconds(500), scheduler: RunLoop.main).sink { [weak self] _ in self?.performLocalSearch() } // to prevent retain cycles to text changes in the search field listener.cancel() }
Brian Voong
4 years ago
David Guarino
4 years ago
I’m a little confused .... adding listener.cancel will stop events from being fired and not cause any memory leaks, but it doesn’t give the app the functionality to display search results after the textField has text. But if taken out search results work but memory leaks occur. Just curious if both work on your end
Brian Voong
4 years ago
Christopher J. Roura
2 years ago
I am not sure if this is an incorrect approach but I was of the thought process that the for my listener, I didn't have one upon the view being loaded so I set it as an optional. I then followed the rest the same but just kept it optional. Do you know if this has any downsides?
HELP & SUPPORT