Skip to content

Instantly share code, notes, and snippets.

@leolelego
Created October 17, 2018 23:42
Show Gist options
  • Save leolelego/308504283e1fa4f323a182a89b4641ba to your computer and use it in GitHub Desktop.
Save leolelego/308504283e1fa4f323a182a89b4641ba to your computer and use it in GitHub Desktop.
UIViewController Template Protocol for Manual View design
import UIKit
class ViewController<T:UIView> : UIViewController{
weak var _view : T! {return self.view as? T}
override func loadView() {
view = T()
}
}
class View:UIView {
override init(frame: CGRect) {
super.init(frame: frame)
initializeLayout()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initializeLayout()
}
func initializeLayout(){
assert(false, "missing inheritance implementation")
}
}
class HomeViewController: ViewController<HomeView> {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class HomeView: View {
override func initializeLayout() {
backgroundColor = .red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment