Last active
March 12, 2017 01:06
-
-
Save efremidze/6090d642d961b1b4b5a66efb363c2616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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