Skip to main content

Command Palette

Search for a command to run...

Inject view model in a view

Updated
0 min readView as Markdown

There are two major patterns I have come across.

  • Pattern 1: init(with viewModel: ViewModel)
  • Pattern 2: init() and render(using viewModel: ViewModel)

Pattern 1 is best with your view should only be rendered with one view model.

Pattern 2 is best if your view needs to be updated with a new view model (e.g. based on an API call).

35 views

More from this blog

CoderLyn's developer journey

136 posts

I'm an iOS developer, helping millennials with their finances through US neo-bank, Empower.

Before making the switch to development, I was a strategist and GM in the tech space.