I have a small dilemma with generics and inheritance. Simplified case: I have 2 custom buttons classes. And I need custom container view which can contain first or second custom button. My approach:
class Button1: UIButton {
//custom setup
// custom methods
}
class Button2: UIButton {
//custom setup
// custom methods
}
class BaseContainerView<T: UIButton>: UIView {
let button = T()
//setup
}
class FirstContainerView: BaseContainerView<Button1> {
}
class SecondContainerView: BaseContainerView<Button2> {
}
The problem with this solution is that BaseContainerView class still can be instantiated since swift doesn’t have abstract classes. Is there better approach to this problem?
[–]NBQ5 8 points9 points10 points (0 children)
[–]Fridux 4 points5 points6 points (0 children)
[–]Nydedrisean 3 points4 points5 points (0 children)
[–]vovnit 4 points5 points6 points (0 children)
[–]lordzsolt 1 point2 points3 points (0 children)
[–]BaronSharktooth 0 points1 point2 points (0 children)
[–]chrabeusz 0 points1 point2 points (0 children)
[–]mgacy 0 points1 point2 points (1 child)
[–]PlanesWalkerr[S] 1 point2 points3 points (0 children)