title: SwiftUI How to pass a global variable to non-View classes
body: <p>I understand how to use @EnvironmentObject to make global data available to any view class, but I can't find a way to pass the variable to a non-view class.</p>
  <p>My situation, which seems like a common issue, is:</p>
  <ol>
  <li>Login, returns an access token. This token is required to be used in all subsequent api calls</li>
  <li>Store access token in a UserSettings class</li>
  <li>Place the UserSettings in an Environment bucket</li>
  </ol>
  <pre><code>    let contentView = ContentView()
          .environmentObject(UserSettings())
  </code></pre>
  <ol start="4">
  <li>Each view will display data based on the data returned in an api call</li>
  </ol>
  <pre><code>struct HomeView: View {
      @EnvironmentObject var user: UserSettings  &lt;=== ACCESS TO GLOBAL DATA
      @ObservedObject var categories = Categories()  &lt;=== GET DATA FOR THIS VIEW
  
      var body: some View {
      ...
  }
  </code></pre>
  <ol start="5">
  <li>Categories() is a non-view Swift class that will retrieve the data, but requires the access token which is stored in UserSettings</li>
  </ol>
  <pre><code>class Categories : ObservableObject {
      @Published var allCategories = CategoriesModel()
      @EnvironmentObject var user: UserSettings  &lt;==== CANNOT ACCESS THIS DATA!
  
      init() {
          fetchCategories(page: 0, pageSize: 20)
      }
  </code></pre>
  <p>UserSettings is empty because this class is not a View struct and doesn't seem to behave like a View class would. Since the access token I need is stored in the UserSettings class, how can I get access to this? Is there an alternative way to store/access this data?</p>