I'm thinking through the structure of a very simple ViewModel and ViewController for a test application. I have something akin to:
FirstViewController.m:
- (IBAction)launchButtonSelected:(id)sender
{
[self.viewModel launchActionSelected];
}
FirstViewModel.m:
- (void)launchActionSelected
{
// [todo] - Figure this out.
}
When the launchButton
is selected in the FirstViewController
, I want to make and present a SecondViewController
.
My questions:
- Is there a solid rule of thumb for where should I create
SecondViewController
's ViewModel? - Who should initialize
SecondViewController
? - Where should I push
SecondViewController
onto the view hierarchy? (i.e. a navigation push or a modal presentation).
I was personally thinking:
- The ViewModel for
SecondViewController
will probably be created in its initializer. This always leads me down a confusing path: what if I want to pass information fromFirstViewModel
toSecondViewModel
? Should I exposeSecondViewModel
as a public property onSecondViewController
so I can get/set values on it? FirstViewController
should createSecondViewController
, andFirstViewController
should pushSecondViewController
onto the screen.
My intuition considers this to be subpar: I'd like to isolate the presentation of ViewControllers a bit more, and have the app be more ViewModel-focused, but this seems difficult to do. (i.e. "push" ViewModels, not ViewControllers… but "push" is intrinsically related to the app's visual presentation, so perhaps that's the wrong way to think about it.)