aboutsummaryrefslogtreecommitdiffstats
path: root/Wireguard/ViewControllers/Identifyable.swift
blob: 43b2de0ec847c8ba7f25fc51fa3b53d397c99e11 (plain) (blame)
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
//
//  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
    }
}