Generic swift iOS "not a subtype of" code compilation error "

I study generics in quick. And I don’t understand what is going wrong.

Someone please explain how I can insert a common template into another template.

BasePresenter class BasePresenter looks like

 class BasePresenter<VIEW : BaseView>{ 

The error code below in the picture:

* UPD *

+5
source share
1 answer

In the class declaration, the type that you seem to type, i.e. PRESENTER, undesirable. I am not sure why the compiler allows this declaration of a partial type, although it later correctly gives an error when trying to create a variable using such a partial type. The workaround for now is to avoid this type and directly declare your presenter variable of type BasePresenter or present a type of PRESENTER using an alias of type:

Sort of -

 class BaseViewController <VIEW: BaseView> : UIViewController, BaseView{ typealias PRESENTER = BasePresenter<VIEW>! var presenter : PRESENTER! //Rest of the class body... } 
0
source

All Articles