Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Last active April 11, 2022 01:03
Show Gist options
  • Save hsleedevelop/4a18e86705b5d62685d791b76f928fea to your computer and use it in GitHub Desktop.
Save hsleedevelop/4a18e86705b5d62685d791b76f928fea to your computer and use it in GitHub Desktop.
Using Generics to simplify subclassing UIViewController’s view
//refs: https://codeinswift.io/using-generics-to-simplify-subclassing-uiviewcontrollers-view-860c90852e27
class ViewController<UI: UIView>: UIViewController {
let ui = UI(frame: UIScreen.main.bounds)
override func loadView() {
self.view = ui
}
}
class ProductsListViewController: ViewController<ProductsListView> {
override func viewDidLoad() {
super.viewDidLoad()
ui.tableView.reloadData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment