aboutsummaryrefslogtreecommitdiffstats
path: root/Wireguard/ViewControllers/Identifyable.swift
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Wireguard/ViewControllers/Identifyable.swift27
1 files changed, 27 insertions, 0 deletions
diff --git a/Wireguard/ViewControllers/Identifyable.swift b/Wireguard/ViewControllers/Identifyable.swift
new file mode 100644
index 0000000..9312afe
--- /dev/null
+++ b/Wireguard/ViewControllers/Identifyable.swift
@@ -0,0 +1,27 @@
+//
+// Identifyable.swift
+// Wireguard
+//
+// Created by Jeroen Leenarts on 23-05-18.
+// Copyright © 2018 Wireguard. All rights reserved.
+//
+
+import Foundation
+import UIKit
+
+public protocol Identifyable: class {
+ static var identifier: String { get }
+}
+
+public extension Identifyable {
+ static var identifier: String {
+ return String(describing: Self.self)
+ }
+}
+
+extension UIStoryboard {
+
+ public func instantiateViewController<T: Identifyable>(type: T.Type) -> T where T: UIViewController {
+ return self.instantiateViewController(withIdentifier: type.identifier) as! T // swiftlint:disable:this force_cast
+ }
+}