Skip to content

Instantly share code, notes, and snippets.

@barisuyar
Created November 7, 2022 13:55
Show Gist options
  • Save barisuyar/ef3eb23325c9fb197340be03a75b7c1a to your computer and use it in GitHub Desktop.
Save barisuyar/ef3eb23325c9fb197340be03a75b7c1a to your computer and use it in GitHub Desktop.
sw VC
final class ViewController: UIViewController {
@IBOutlet private weak var tableView: UITableView!
@IBOutlet private weak var searchTextField: UITextField!
@Filtered() var people: [Person] = [
.init(name: "Luke Skywalker", height: 172, gender: "male"),
.init(name: "Darth Vader", height: 202, gender: "male"),
.init(name: "Leia Organa", height: 150, gender: "female"),
.init(name: "Owen Lars", height: 178, gender: "male"),
.init(name: "Beru Whitesun Lars", height: 165, gender: "female")
]
@IBAction func editingChanged(_ sender: UITextField) {
_people.filterString = searchTextField.text ?? ""
tableView.reloadData()
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
_people.filtered.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = _people.filtered[indexPath.row].name
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment