Be Careful When you Initialize a StateObject Property Wrapper — https://jaredsinclair.com/2024/03/14/state-object-autoclosure.html

There’s an easy pitfall to fall into, and it can totally undermine the reason you're using StateObject in the first place.

Jared Sinclair | Be Careful When You Initialize a State Object

@jaredsinclair I am so bookmarking this to read later.
@jaredsinclair Good article, but I tried your suggestion and the compiler doesn't like it…?
@adam Thanks. I was typing the code samples straight into Markdown from memory.
@adam I'll push up some fixes in a bit.
@adam This is exactly why an autoclosure here is so misleading.

@jaredsinclair Great post! Small clarification on explicit view identity: the .id() modifier acts in *addition* to the structural identity defined by the view’s position in the view hierarchy. So .id() can never make two non-identical views identical, only the other way around. These two views have different identity despite having the same .id():

if flag {
MyView().id("one")
} else {
MyView().id("one")
}

@jaredsinclair any thoughts re: Apples recommendation to use State (instead of StateObject) in combination with Observation? Because in my testing this is not working at all.
@jaredsinclair this is an excellent summary! I put off writing about this for over a year, and now I'm happy to scrap the draft and just link to yours :)
@ctietze lol mine took over a year as well
@jaredsinclair ha, maybe it's part of the complexity of this ... uh.. """interesting tool""" :)