Last active
October 26, 2015 12:58
-
-
Save tolpp/c85ccd1cfa81ef884a0b to your computer and use it in GitHub Desktop.
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
/// instantiates component from storyboard by given storyboard name and identifier | |
protocol IBInstantiatable { | |
/// Storyboard name that component designed in | |
static var storyboardName : String {get} | |
/// component identifier that assigned to component in storyboard | |
/// | |
/// `Identity -> Storyboard ID` | |
static var identifier : String {get} | |
} | |
extension IBInstantiatable where Self : UIViewController { | |
/// Instantiates `UIViewControl` from storyboard | |
static func instantiate() -> Self? { | |
return UIStoryboard(name: storyboardName, bundle: nil).instantiateViewControllerWithIdentifier(identifier) as? Self | |
} | |
} |
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
let vc = MyCustomViewController.instantiate() |
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
class MyCustomViewController: UIViewController { | |
//UIViewController staff | |
} | |
extension MyCustomViewController : IBInstantiatable { | |
static var storyboardName : String {get{return "StoryboardName"}} | |
static var identifier : String {get{return "identifier"}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment