I have a class Superclass
with generic type UIView
. The class Subclass
inherits from Superclass
:
class Superclass<T: UIView>: UIViewController { ... }
class Subclass: Superclass<UIButton> { ... }
And now, from another UIViewController
I am trying to initialise an object of type Subclass
like this:
let childViewController: Superclass<UIView>?
switch type {
case .typeOne:
childViewController = Subclass()
default:
childViewController = nil
}
But is is throwing the following error:
Cannot assign value of type 'Subclass' to type 'Superclass<UIView>?'
How can I specify that I want to initialise the childViewController
with a UIButton
type, for example?
Thanks!