-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppStoryboard.swift
45 lines (38 loc) · 1.44 KB
/
AppStoryboard.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// AppStoryboard.swift
//
// Created by Pushpank on 12/10/2019.
// Copyright © 2019 Pushpank. All rights reserved.
//
// swiftlint:disable identifier_name
import UIKit
enum AppStoryboard: String {
case TabBar
case Authentication
case Home
}
extension AppStoryboard {
var instance: UIStoryboard {
return UIStoryboard(name: self.rawValue, bundle: Bundle.main)
}
func viewController<T: UIViewController>(viewControllerClass: T.Type, function: String = #function, line: Int = #line, file: String = #file) -> T {
let storyboardID = (viewControllerClass as UIViewController.Type).storyboardID
guard let scene = instance.instantiateViewController(withIdentifier: storyboardID) as? T else {
fatalError("ViewController with identifier \(storyboardID), not found in \(self.rawValue) Storyboard.\nFile : \(file) \nLine Number : \(line) \nFunction : \(function)")
}
return scene
}
func initialViewController() -> UIViewController? {
return instance.instantiateInitialViewController()
}
}
extension UIViewController {
// Not using static as it wont be possible to override to provide custom storyboardID then
class var storyboardID: String {
let vcName = "\(self)"
return vcName
}
static func instantiate(fromAppStoryboard appStoryboard: AppStoryboard) -> Self {
return appStoryboard.viewController(viewControllerClass: self)
}
}