Last active
January 14, 2021 16:52
-
-
Save thepearl/4c51d2e7f36c31eef093d8dcd729cacb to your computer and use it in GitHub Desktop.
setting up observers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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