Created
January 14, 2021 16:32
-
-
Save thepearl/4be2c3faaeb0a8cc8d4be68fdb6eb44c to your computer and use it in GitHub Desktop.
Implementing @published to UISearchBar Delegate
This file contains hidden or 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 | |
{ | |
@IBOutlet weak var searchBar: UISearchBar! | |
@IBOutlet weak var tableView: UITableView! | |
@Published var keyStroke: String = "" | |
override func viewDidLoad() | |
{ | |
super.viewDidLoad() | |
registerCell() | |
} | |
} | |
// MARK: - Setup UI & Cells | |
extension MainView | |
{ | |
func registerCell() | |
{ | |
let movieCell = UINib(nibName: MovieCell.reuseIdentifier, bundle: nil) | |
tableView.register(movieCell, forCellReuseIdentifier: MovieCell.reuseIdentifier) | |
} | |
} | |
//MARK: - UISearchBar Delegate | |
extension MainView: UISearchBarDelegate | |
{ | |
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) | |
{ | |
self.keyStroke = searchText | |
} | |
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { | |
self.keyStroke = "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment