Created
December 26, 2016 12:56
-
-
Save kitasuke/df2d682e7c5b54a6d4477d9d91ff2a1a 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
import UIKit | |
protocol StoryboardInstantiable { | |
static var storyboardName: String { get } | |
static var storyboardIdentifier: String { get } | |
} | |
extension StoryboardInstantiable where Self: UIViewController { | |
static var storyboardName: String { return String(describing: self) } | |
static var storyboardIdentifier: String { return String(describing: self) } | |
static func instantiateFromStoryboard() -> Self { | |
let storyboard = UIStoryboard(name: storyboardName, bundle: nil) | |
if let viewController = storyboard.instantiateInitialViewController() as? Self { | |
return viewController | |
} | |
return storyboard.instantiateViewController(withIdentifier: storyboardIdentifier) as! Self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment