Skip to content

Instantly share code, notes, and snippets.

@jeamesbone
Created October 19, 2016 03:55
Show Gist options
  • Save jeamesbone/76dca283964a1f2affd5f28564d899bd to your computer and use it in GitHub Desktop.
Save jeamesbone/76dca283964a1f2affd5f28564d899bd to your computer and use it in GitHub Desktop.
Storyboard Dependency Injection - UIStoryboard+Scenes.swift
extension UIStoryboard {
func instantiateViewController<S: Scene>(for scene: S) -> S.ViewController {
guard let viewController = instantiateViewController(withIdentifier: scene.identifier) as? S.ViewController
else {
fatalError("expected view controller with identifier '\(scene.identifier)' to be of type '\(String(describing: S.ViewController.self))'")
}
scene.configureViewController(viewController)
return viewController
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment