Michael Long
Sep 25, 2023

--

I'd have to dive into this, but I don't think you're seeing quite what you think you're seeing. Yes, given your code a new model is created. That said, State will probably not be using it since it's maintaining state based on view identity and only the first instance should actually be used.

The reason you don't see the same with StateObject is based on how StateObject uses a thunked auto closure to create the instance.

--

--

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)