Clean Code and User Multiple Storyboards (TO NO CONFLICT .storyboard )

import Foundation
import UIKit

enum AppStoryboard : String {

case Main

var instance : UIStoryboard {

return UIStoryboard(name: self.rawValue, bundle: Bundle.main)
}

func viewController(viewControllerClass : T.Type, function : String = #function, line : Int = #line, file : String = #file) -> T {

let storyboardID = (viewControllerClass as UIViewController.Type).storyboardID

guard let scene = instance.instantiateViewController(withIdentifier: storyboardID) as? T else {

fatalError("ViewController with identifier \(storyboardID), not found in \(self.rawValue) Storyboard.\nFile : \(file) \nLine Number : \(line) \nFunction : \(function)")
}

return scene
}

func initialViewController() -> UIViewController? {

return instance.instantiateInitialViewController()
}
}

extension UIViewController {

// Not using static as it wont be possible to override to provide custom storyboardID then
class var storyboardID : String {

return "\(self)"
}

static func instantiate(fromAppStoryboard appStoryboard: AppStoryboard) -> Self {

return appStoryboard.viewController(viewControllerClass: self)
}
}

////////

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//
// let greenScene = ViewController2.instantiate(fromAppStoryboard: .storyboard2)
//
let greenScene2 = AppStoryboard.storyboard2.viewController(viewControllerClass: ViewController2.self)
//
// let greenScene3 = AppStoryboard(rawValue: "storyboard2")?.instance.instantiateViewController(withIdentifier: ViewController2.storyboardID)

}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let greenScene2 = AppStoryboard.storyboard2.viewController(viewControllerClass: ViewController2.self)
self.present(greenScene2, animated: true, completion: nil)

}
}

nguồn : https://medium.com/@gurdeep060289/clean-code-for-multiple-storyboards-c64eb679dbf6