Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created December 15, 2015 23:31
Show Gist options
  • Save jarsen/95b1203105d4a34129e6 to your computer and use it in GitHub Desktop.
Save jarsen/95b1203105d4a34129e6 to your computer and use it in GitHub Desktop.
protocol StoryboardInstantiable {
static var storyboardName: String { get }
static var storyboardIdentifier: String { get }
}
extension StoryboardInstantiable {
static func instantiateFromStoryboard() -> Self {
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
guard let vc = storyboard.instantiateViewControllerWithIdentifier(storyboardIdentifier) as? Self else {
fatalError("Instantiated view controller does not match type")
}
return vc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment