Skip to content

Instantly share code, notes, and snippets.

@lucaswkuipers
Last active July 11, 2022 22:12
Show Gist options
  • Save lucaswkuipers/3e64ed113df5668aa4a46f4ba144c11d to your computer and use it in GitHub Desktop.
Save lucaswkuipers/3e64ed113df5668aa4a46f4ba144c11d to your computer and use it in GitHub Desktop.
import UIKit
protocol ReusableViewControllerDelegate {
func handle(_ event: ReusableViewController.Event)
}
final class ReusableViewController: UIViewController {
enum Event {
case viewDidLoad
case viewWillAppear(_ animated: Bool)
}
var delegate: ReusableViewControllerDelegate?
private let contentView: UIView
init(with view: UIView) {
self.contentView = view
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func loadView() {
super.loadView()
self.view = contentView
}
override func viewDidLoad() {
super.viewDidLoad()
delegate?.handle(.viewDidLoad)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
delegate?.handle(.viewWillAppear(animated))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment