AnasAlhasani / Marvel

Marval iOS application with a generic-based API client using UIKit, Combine and MVVM with clean architecture concepts 🚀.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refactor ViewModels using Input/Output with Combine

AnasAlhasani opened this issue · comments

Refactor ViewModel to fully use combine and update views. This can be achieved using:

protocol ViewModel { 
    associatedType Input 
    associatedType Output 

    func transform(input: Input) -> Output 
}

Then, i.e CharactersViewModel should conform to ViewModel generic protocol:

final class CharactersViewModel: ObservableObject { 

}

extension CharactersViewModel: ViewModel { 
    struct Input { }
    struct Output { }
    
    func transform(input: Input) -> Output { 
        // code here ..
    }  
}