Last active
January 24, 2019 19:55
-
-
Save hamsternik/bf2ab86cd0f3fa3e1ccad69cb09e53bd to your computer and use it in GitHub Desktop.
Easy storyboard & nib initialization by the concrete class from the static method
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
class YourCustomViewController: UIViewController { | |
static func storyboardInstance() -> YourCustomViewController? { | |
// if your storyboard's name same as VC name | |
let storyboard = UIStoryboard(name: String(describing: self), bundle: nil) | |
// make concrete storyboard as initial to use this method | |
// else, use instantiateViewController(withIdentifier: _ ) | |
return storyboard.instantiateInitialViewController() as? YourCustomViewController | |
} | |
} | |
//============================================================================================ | |
class LoginView: UIView { | |
static func nibInstance() -> LoginView? { | |
let nib = Bundle.main.loadNibNamed(String(describing: self), owner: nil, options: nil) | |
return nib?.first as? LoginView | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// More general solution