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()
}