Created
October 17, 2018 23:42
-
-
Save leolelego/308504283e1fa4f323a182a89b4641ba to your computer and use it in GitHub Desktop.
UIViewController Template Protocol for Manual View design
This file contains hidden or 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 | |
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