[ad_1]
extension UIViewController {
static func instantiate() -> Self? {
let identifier = String(describing: self)
let identify = identifier.replacingOccurrences(of: "VC", with: "")
let storyboard = UIStoryboard(identify: identify, bundle: Bundle.most important)
return storyboard.instantiateViewController(identifier: identifier) as? Self
?? storyboard.instantiateInitialViewController() as? Self
}
}
Runtime error:
Storyboard would not include a view controller with identifier
Why does it crash? Why do not simply silently return nil? Would not or not it’s extra intuitive, constant and handy method?
And the way am I purported to cope with this example now, to lively my aim?
Edit: In docs they are saying
If the desired identifier doesn’t exist within the storyboard file,
this technique raises an exception.
Then why is not this technique marked as “throws”? How am I purported to catch the exception from operate, which does not “throw”?
[ad_2]
