Last active
September 17, 2020 14:31
-
-
Save khanlou/1da2699e4c03827d89927de0bcd858ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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 StoryboardInitializable { | |
| static var storyboardName: String { get } | |
| static var storyboardIdentifier: String { get } | |
| static func makeFromStoryboard() -> Self | |
| } | |
| extension StoryboardInitializable { | |
| static var storyboardName: String { | |
| return String(describing: self) | |
| } | |
| static var storyboardIdentifier: String { | |
| return String(describing: self) | |
| } | |
| static func makeFromStoryboard() -> Self { | |
| let storyboard = UIStoryboard(name: storyboardName, bundle: nil) | |
| let optionalViewController = storyboard.instantiateViewController(withIdentifier: storyboardIdentifier) as? Self | |
| guard let viewController = optionalViewController else { fatalError() } | |
| return viewController | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment