let's say, I have UIViewController subclass:
class InformationServiceMenuVC <T : InformationServiceItemProtocol>: UITableViewController {
}
normally I can create instance of view controller by calling something like:
let vc = InformationServiceSideMenuVC<InformationServiceMenuItem>()
but how do I pass needed generic type when use storyboard?
The answer is YES! Here we will be discussing a simple way to use SwiftUI into our existing project, which already consists of a storyboard. Let's dive in then!
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
Create a concrete class that inherits from the generic class:
class SpecificInformationServiceMenuVC : InformationServiceMenuVC<Specific> {}
Then you can use the specific subclass as your class type in storyboard.
It might even work to just make a typealias:
typealias SpecificInformationServiceMenuVC = InformationServiceMenuVC<Specific>
In Swift 3.0.1, I was able to refactor from this:
class TagPickerViewController: BaseViewController, HasAppController {
}
extension TagPickerViewController: UITableViewDelegate {
}
to:
class TagPickerViewControllerGeneric<TagViewModelClass: TagPickerViewModel>
: BaseViewController {
}
class TagPickerViewController: TagPickerViewControllerGeneric<TagPickerViewModel>,
HasAppController, UITableViewDelegate {
}
While keeping TagPickerViewController
in storyboard/xib. Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With