ios – Utilizing 2 sort of ViewModel Protocol with similar ViewController?

0
157
ios – Utilizing 2 sort of ViewModel Protocol with similar ViewController?


I’m making an attempt to make my viewmodel interfaces extra conformant to SOLID by eradicating unused strategies by splitting them down into smaller interfaces.

Nonetheless I cant appear to get this to work with ViewModel Interfaces and ViewControllers

if i’ve these 2 instance protocols

protocol PlayerViewModel: ViewModelProtocol {
    var title: String { get }
    var sort: Enum { get }
    var stateIs: Bool { get }
}

protocol OnlinePlayerViewModel: PlayerViewModel {
    var isFromA: Bool { get }
    var isFromB: Bool { get }
    var hasIntro: Bool { get }
    var hasSkipped: Bool { get set }

    func sendEvent()
    func sendAnalytics()
}

So in my VC i have to entry all of the properties in OnlinePlayerViewModel so in my class i would like a reference equivalent to

init(_ viewModel: OnlinePlayerViewModel) {
        _viewModel = viewModel

        tremendous.init(nibName: nil, bundle: nil)
}

non-public var _viewModel: OnlinePlayerViewModel

Nonetheless i’ve one other ViewModel for offline behaviours that solely wants PlayerViewModel so i cant init with it because it wont set to non-public var _viewModel: OnlinePlayerViewModel

What the answer right here? so i dont must drive offline view mannequin to evolve to OnlinePlayerViewModel and have loads of uneeded clean capabilities and values, whislt reusing my viewcontroller…or is that this simply not doable?

Thanks!