Michael Long
Nov 30, 2021

--

An environmentObject of that type is basically a view model... and you don't want your view models to be protocols.

I wrote about this at some length here: https://betterprogramming.pub/swiftui-view-models-are-not-protocols-8c415c0325b1

But basically you want to change the data on which your environment object depends, not the object itself. To do otherwise and swap out the environment object itself greatly reduces the chances of your finding and noticing any problems your implementation might have.

--

--

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)