is there a way to override sceneStoryboard for StoryboardSceneBased
mansoor92 opened this issue · 2 comments
mansoor92 commented
i want to subclass a view controller but cannot override sceneStoryboard property.
Both parent and child viewControllers are from different storyboards
calmez commented
You can in a class that immediately declares conformance to the protocol re-define the static var.
Example:
class MyStoryboardBasedViewController: UIViewController, StoryboardBased {
static var sceneStoryboard: UIStoryboard {
return UIStoryboard(name: "MyCustomStoryboard", bundle: Bundle(for: self))
}
}
However, keep in mind that in subclasses of MyStoryboardBasedViewController
you will not be able to override that static var ... because it's a static var ... 😄
If you want to do that you will probably want to relay the static var to a class var that you can override in subclasses.
AliSoftware commented
You should indeed be able to use class var
instead of static var
class BaseViewController: UIViewController, StoryboardBased {
class var sceneStoryboard: UIStoryboard {
UIStoryboard(name: "BaseVC", Bundle(for: self))
}
}
class ChildViewController: BaseViewController {
override class var sceneStoryboard: UIStoryboard {
UIStoryboard(name: "ChildVC", Bundle(for: self))
}
}
let vc = ChildViewController.instantiate() // Uses ChildVC as storyboard