Michael Long
Jan 23, 2025

--

This is incorrect. StateObject's thunk initializer will capture the value passed in the @autoclosure and again create external storage for the reference, but the object itself won't be recreated. (Add an init and breakpoint it to see these.)

What can happen with double state objects are obscure rendering issues when a change causes both state objects to trigger updates.

--

--

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)