Michael Long
Mar 13, 2022

--

If you were to create AccountListLoadingView() with no parameters then StateObject would construct and use its default value when the body is referenced.

But you can also instantiate the view passing in the parameter instead. In which case AccountListLoadingView will take the value passed into its synthesized initializer and create the StateObject using the passed value as its default value.

The following SO page might shed some more light on the process,

https://stackoverflow.com/questions/62635914/initialize-stateobject-with-a-parameter-in-swiftui

--

--

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)