|
// Creates enums Segues, Storyboards and ViewIdentifiers for segues and instantiations. |
|
extension UIViewController { |
|
|
|
public enum Segues: String { |
|
case loginHome = "loginHomeSegue" |
|
} |
|
|
|
public enum Storyboards: String { |
|
case main = "Main" |
|
case profile = "Profile" |
|
} |
|
|
|
public enum ViewIdentifiers: String { |
|
case login = "Login" |
|
case home = "Home" |
|
} |
|
|
|
public func performSegue(withIdentifier identifier: Segues) { |
|
performSegue(withIdentifier: identifier.rawValue, sender: nil) |
|
} |
|
|
|
/// Returns an instance of UIViewController subclass |
|
/// |
|
/// - Parameters: |
|
/// - storyboard: The *name* of the storyboard in which the view is located. |
|
/// - identifier: The *storyboard id* property of the view. |
|
/// - controller: The *UIViewController subclass* associated with the view. |
|
/// - presentation: The *UIModalPresentationStyle*, default value is .fullScreen |
|
public func instantiateVC<T: UIViewController>(storyboard: Storyboards, identifier: ViewIdentifiers, controller: T.Type, presentation: UIModalPresentationStyle? = .fullScreen) -> T { |
|
let storyboard = UIStoryboard(name: storyboard.rawValue, bundle: nil) |
|
let viewController = storyboard.instantiateViewController(withIdentifier: identifier.rawValue) as! T |
|
viewController.modalPresentationStyle = presentation! |
|
|
|
return viewController |
|
} |
|
} |
|
|
|
// Usage: |
|
// When preparing for segue |
|
// override func prepare(for segue: UIStoryboardSegue, sender: Any?) { |
|
// switch segue.identifier { |
|
// case Segues.loginHome.rawValue: |
|
// let destinationVC = segue.destination as! HomeViewController |
|
// destinationVC.<#someVariable#> = <#someValue#> |
|
// default: |
|
// return |
|
// } |
|
// } |
|
|
|
// When performing a segue |
|
// performSegue(withIdentifier: .loginHome) |
|
|
|
// When instantiating a view |
|
// let vc = instantiateVC(storyboard: .main, identifier: .login, controller: LoginViewController.self, presentation: .fullScreen) |
|
// vc.<#someVariable#> = <#someValue#> |
|
// present(vc, animated: false) |