Skip to content

Instantly share code, notes, and snippets.

@thepearl
Last active January 14, 2021 16:52
Show Gist options
  • Save thepearl/4c51d2e7f36c31eef093d8dcd729cacb to your computer and use it in GitHub Desktop.
Save thepearl/4c51d2e7f36c31eef093d8dcd729cacb to your computer and use it in GitHub Desktop.
setting up observers
import UIKit
import Combine
class MoviesTableViewDiffableDataSource: UITableViewDiffableDataSource<String?, Result> {}
class MainView: UIViewController
{
var cancellables: Set<AnyCancellable> = []
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var tableView: UITableView!
@Published var keyStroke: String = ""
override func viewDidLoad()
{
super.viewDidLoad()
registerCell()
setupObservers()
}
}
//MARK: - Observers
extension MainView
{
func setupObservers()
{
// MONITOR search bar textfield keystrokes
$keyStroke
.receive(on: RunLoop.main)
.sink { (keyWordValue) in
print(keyWordValue)
}.store(in: &cancellables)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment