Michael Long
Apr 3, 2023

--

If you look at the very last code example you can see the problem. I want to initialize the VM with the item. You can do it passing the item to the view, but then you have to write your own initializer and do the rather weird _viewModel = StateObject(wrappedValue: ItemViewModel(item: item)) trick.

Not saying you shouldn't do that, but I'm seeing a lot of code that's doing the on-the-fly VM creation and that's what I'm calling out.

People think that OO is good for ANY passed ObservableObject, and that's not the case.

--

--

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.

No responses yet