-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewControllersFactory.swift
More file actions
36 lines (27 loc) · 1.04 KB
/
ViewControllersFactory.swift
File metadata and controls
36 lines (27 loc) · 1.04 KB
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
//
// ViewControllersFactory.swift
//
// Created by Or Elmaliah on 07/01/2017.
// Copyright © 2017 Or Elmaliah. All rights reserved.
//
import UIKit
protocol StoryboardIdentifiable {
static var storyboardIdentifier: String { get }
}
extension StoryboardIdentifiable where Self: UIViewController {
static var storyboardIdentifier: String {
return String(describing: self)
}
}
enum ViewControllersFactoryStoryboardType: String {
case main = "Main"
}
final class ViewControllersFactory: NSObject {
static func instantiateViewController<T: UIViewController>(inStoryboard type: ViewControllersFactoryStoryboardType) -> T where T: StoryboardIdentifiable {
let storyboard = UIStoryboard(name: type.rawValue, bundle: nil)
guard let viewController = storyboard.instantiateViewController(withIdentifier: T.storyboardIdentifier) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
}
return viewController
}
}