Closed AYastrebov closed 7 years ago
I wonder why do you want to hide it with protocol?
The idea is that ViewController
receive concrete implementation of view model, where all other dependencies can be injected via ViewModel
initializer
Ok, I've got it
I guess - for the sake of easily testing View Controller with UI / Snapshot tests.
So, my idea is to hide ViewModel implementation with protocol
something like this:
protocol PostsViewModelType: ViewModelType {}
final class PostsViewModel: PostsViewModelType {}
And then, in viewController, access the viewModel like so:
var viewModel: PostsViewModelType
But I am getting the folowing error, when accessing viewModel
Protocol 'PostsViewModelType' can only be used as a generic constraint because it has Self or associated type requirements
This happens because of
associatedtype
, but unfortunately I couldn't figure out how to resolve this. Do you have any thoughts about this?