Created
April 16, 2019 06:52
-
-
Save teddichiiwa/8da9baabe041f8e35f284435b4cee14e to your computer and use it in GitHub Desktop.
Coordinator Pattern with Storyboards
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: NSObjectProtocol { | |
associatedtype MyType | |
static var defaultFileName: String { get } | |
static func instantiateViewController(_ bundle: Bundle?) -> MyType | |
} | |
extension StoryboardInstantiable where Self: UIViewController { | |
static var defaultFileName: String { | |
return NSStringFromClass(Self.self).components(separatedBy: ".").last! | |
} | |
static func instantiateViewController(_ bundle: Bundle? = nil) -> Self { | |
let fileName = defaultFileName | |
let sb = UIStoryboard(name: fileName, bundle: bundle) | |
return sb.instantiateInitialViewController() as! Self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment