1

I have two custom mappable models

class FirstModel: Mappable, CustomProtocol {

}

class SecondModel: FirstModel {

}

And another class like this

class SomeViewController<T: CustomProtocol>: AnotherViewConyroller<T> {

}

Now, in one of my viewController, i'm trying to assign different Model to reuse the current class.

var controller = SomeViewController<FirstModel>
controller = SomeViewController<SecondModel>

On the last line, i'm getting this error

Cannot assign value of type SomeViewController<FirstModel> to type
SomeViewController<SecondModel>

I don't know am i doing wrong. FirstModel is conforming to CustomProtocol and SecondModel is subclassing it.

Haseeb Iqbal
  • 1,455
  • 13
  • 20
  • What are you even trying to do? You create the controller here as SomeViewController. Then you try to redefine it as another type? What are you trying to achieve? – andromedainiative Jan 16 '19 at 09:58
  • SomeViewController has some pagination-based networking logic. Models (FirstModel/SecondModel or any other) are then used to parse the API response. I want to use different model in another scenario – Haseeb Iqbal Jan 16 '19 at 10:02
  • You won't be able to reassign your controller like that by assigning it as a different class. Look at the MVVM pattern if you wanna use updated view model for the same controller. – andromedainiative Jan 16 '19 at 10:05
  • SomeViewController requires CustomProtocol. FirstModel is conforming to CustomProtocol and SecondModel is a subclass of FirstModel Now here i'm declaring variable as parent type var controller = SomeViewController Shouldn't it work? What is the issue here? Am i understanding something wrong? – Haseeb Iqbal Jan 16 '19 at 10:08

0 Answers0