Skip to content

Instantly share code, notes, and snippets.

@efremidze
Last active March 12, 2017 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efremidze/6090d642d961b1b4b5a66efb363c2616 to your computer and use it in GitHub Desktop.
Save efremidze/6090d642d961b1b4b5a66efb363c2616 to your computer and use it in GitHub Desktop.
enum AppStoryboard: String {
case Main
var instance: UIStoryboard {
return UIStoryboard(name: rawValue, bundle: Bundle.main)
}
func viewController<T: UIViewController>(of type: T.Type) -> T {
return instance.instantiateViewController(withIdentifier: type.storyboardId) as! T
}
}
extension UIViewController {
class var storyboardId: String {
return "\(self)"
}
// static func instantiate(from appStoryboard: AppStoryboard) -> Self {
// return appStoryboard.viewController(of: self)
// }
}
protocol Instantiatable {}
extension Instantiatable where Self: UIViewController {
static func instantiate() -> Self {
return AppStoryboard.Main.viewController(of: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment