Skip to content

Instantly share code, notes, and snippets.

@tolpp
Last active October 26, 2015 12:58
Show Gist options
  • Save tolpp/c85ccd1cfa81ef884a0b to your computer and use it in GitHub Desktop.
Save tolpp/c85ccd1cfa81ef884a0b to your computer and use it in GitHub Desktop.
/// 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
}
}
let vc = MyCustomViewController.instantiate()
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