While talking to developers we get a lot of questions on how to initialize a @StateObject with external values.

Today we update our docs by greatly expanding around all our data flow primitives with special attention to StateObject. You'll find better explanations on how to initialize StateObject with external data and few words around what to pay attention when doing so (https://developer.apple.com/documentation/swiftui/stateobject)

We hope this helps everyone get more clarity and understanding on how to work with SwiftUI.

StateObject | Apple Developer Documentation

A property wrapper type that instantiates an observable object.

Apple Developer Documentation

@lucabernardi thank you so much for this! Glad to see that it reflects discussions I’ve soon on Ask Apple and here on Mastodon.

One thing that’s new to me is the autoclosure in the StateObject initializer with external value. I understand what it does for simple data types.

Does the autoclosure in initializer work the same way for richer and more stateful objects? I have to test my setup a bit and find out.