I have a view inside of a Form. The view makes use of a@StateObject property. When I the view loads the state object property is initialised, when I scroll the view so it is off screen and back again the state object is initialised again. Is this expected behaviour?
Below is small sample to reproduce the issue. I have not confirmed it but I suspect the behaviour is the same with a LazyVStack in a ScrollView
Below is small sample to reproduce the issue. I have not confirmed it but I suspect the behaviour is the same with a LazyVStack in a ScrollView
Code Block swift struct MyForm: View { var body: some View { Form { InnerView() /*other form view content*/ } } } struct InnerView: View { @StateObject private var viewModel = ViewModel() var body: some View { Text("Hello") } } struct ViewModel { init() { print("initialised") } }