title: What is the difference between ObservedObject and StateObject in SwiftUI
body: <p>If I have an <code>ObservableObject</code> in SwiftUI I can refer to it as an <code>@ObservedObject</code>:</p>
  <pre><code>class ViewModel: ObservableObject {
      @Published var someText = &quot;Hello World!&quot;
  }
  
  struct ContentView: View {
      @ObservedObject var viewModel = ViewModel()
      
      var body: some View {
          Text(viewModel.someText)
      }
  }
  </code></pre>
  <p>Or as a <code>@StateObject</code>:</p>
  <pre><code>class ViewModel: ObservableObject {
      @Published var someText = &quot;Hello World!&quot;
  }
  
  struct ContentView: View {
      @StateObject var viewModel = ViewModel()
  
      var body: some View {
          Text(viewModel.someText)
      }
  }
  </code></pre>
  <p>But what's the actual difference between the two? Are there any situations where one is better than the other, or they are two completely different things?</p>