forked from euroboy/RMVIPERModuleGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstantiable.swift
More file actions
23 lines (20 loc) · 735 Bytes
/
Instantiable.swift
File metadata and controls
23 lines (20 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import UIKit
protocol Instantiable: AnyObject {
static func instantiate() -> Self
}
extension Instantiable where Self: UIViewController
{
/*
Storyboard name should be the same as UIViewController
Ex: HomeViewController.swift -> Home.storyboard
*/
static func instantiate() -> Self
{
let fullName = NSStringFromClass(self)
let className = fullName.components(separatedBy: ".")[1]
let storyboardName = className.replacingOccurrences(of: "ViewController", with: "")
let storyboard = UIStoryboard(name: storyboardName, bundle: Bundle.main)
let result = storyboard.instantiateViewController(withIdentifier: className) as! Self
return result
}
}