title: Accessing StateObject's object without being installed on a View. This will create a new instance each time - SwiftUI
body: <p>I have to do some initial setup each time the app starts, but I'm getting the error:</p>
  <p><a href="https://i.stack.imgur.com/6wuGd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6wuGd.png" alt="enter image description here" /></a></p>
  <p>The error is clear, the answer is not. I tried putting the init in a subview, but I can't, it needs to be in the root <code>@main</code>. This is how I have it defined:</p>
  <pre><code>@StateObject private var amplifyConfig: AmplifyConfig = AmplifyConfig()
  
  init() {
      if(amplifyConfig.isAmplifyConfigured == false) {
          amplifyConfig.dataStoreHubEventSubscriber()
          amplifyConfig.configureAmplify()
      }
  }
  </code></pre>
  <p>How do I get rid of that warning and actually implement it so it doesn't create multiple instances, at the end of the day that's why I'm using @EnvironmentObject for?</p>