Michael Long
Feb 4, 2024

--

A view model's area of responsibility is its own view.

I'd also avoid passing VM's into child views. The fact that a view has a view model (or not) should be private to the view. Exposing it to the outside complicates that calling sites and makes refactoring those views more problematic.

You've also got a lot of boilerplate here, which would be nice to eliminate. Should consider trying to reduce this down to a view modifier similar to that of navigationDestination.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)