Created
June 21, 2022 05:23
-
-
Save lucaswkuipers/7fe752f8bd956cf3224a354d40edf5e4 to your computer and use it in GitHub Desktop.
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 | |
protocol ReusableViewControllerViewDidLoadDelegate { | |
func viewDidLoad() | |
} | |
protocol ReusableViewControllerViewWillAppearDelegate { | |
func viewWillAppear(_ animated: Bool) | |
} | |
final class ReusableViewController: UIViewController { | |
var viewDidLoadDelegate: ReusableViewControllerViewDidLoadDelegate? | |
var viewWillAppearDelegate: ReusableViewControllerViewWillAppearDelegate? | |
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() | |
viewDidLoadDelegate?.viewDidLoad() | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
viewWillAppearDelegate?.viewWillAppear(animated) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment