title: SwiftUI View memory lifecycle
body: <p>I have main View which has ViewModel and it's declared like this </p>
  
  <p><code>@ObservedObject var viewModel = ViewModel()</code></p>
  
  <p>Everything works perfectly but when I move the app to background and then to foreground the View recreates itself as well as my viewModel and everything stored in viewModel disappears. </p>
  
  <p>In this case making ViewModel a singleton class will solve the problem but making all ViewModels singleton classes is not a good idea. </p>
  
  <p>Is there a workaround for this ?  </p>