1.初版
import UIKit
class CBhelpManager: NSObject {
static let shared = CBhelpManager()
func getViewController(storyboard: String, viewController: String) -> UIViewController {
let storyboard = UIStoryboard.init(name: storyboard, bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: viewController)
return vc
}
}
2.优化版
import UIKit
class XYHelper: NSObject {
static func getViewController(storyboardStr: String?, viewController: String) -> UIViewController {
var storyboard = UIStoryboard()
if let storyboardStr = storyboardStr {
storyboard = UIStoryboard.init(name: storyboardStr, bundle: nil)
}else {
storyboard = UIStoryboard.init(name: "Main", bundle: nil)
}
let vc = storyboard.instantiateViewController(withIdentifier: viewController)
return vc
}
}