Skip to content

Instantly share code, notes, and snippets.

@twittemb
Created February 4, 2018 20:16
Show Gist options
  • Select an option

  • Save twittemb/1e1bc5def144d14e3e7f7f26f777088b to your computer and use it in GitHub Desktop.

Select an option

Save twittemb/1e1bc5def144d14e3e7f7f26f777088b to your computer and use it in GitHub Desktop.
public protocol StoryboardBased: class {
static var storyboard: UIStoryboard { get }
}
public extension StoryboardBased {
static var storyboard: UIStoryboard {
return UIStoryboard(name: String(describing: self), bundle: Bundle(for: self))
}
}
public extension StoryboardBased where Self: UIViewController {
static func instantiate() -> Self {
guard let vc = storyboard.instantiateInitialViewController() as? Self else {
fatalError("The VC of \(sceneStoryboard) is not of class \(self)")
}
return vc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment