title: How to handle data and data models in SwiftUI
body: <p>I am having trouble with the structure of my data for creating a <code>List</code> in <code>SwiftUI</code>. Before <code>SwiftUI</code> I created my data models and held this data in separated files. For example,</p>
  
  <p>In my <code>UserModel.swift</code> :</p>
  
  <pre><code>import SwiftUI
  
  struct UserModel: Equateable {
  
      var name: String
      var items = [ItemModel]()
  
      init(name: String, items: [ItemModel]? = nil) {
          self.name = name
          if let items = items {
              self.items = items
          }
      }
  }
  </code></pre>
  
  <p>In my <code>ItemModel.swift</code> :</p>
  
  <pre><code>import SwiftUI
  
  struct ItemModel: Equatable {
      var itemName: String
      var price: Double
  
      init(itemName: String, price: Double) {
          self.itemName = itemName
          self.price = price
      }
  }
  </code></pre>
  
  <p>Then I had a separate class called <code>Data</code> that held this data.</p>
  
  <p>In my <code>Data.swift</code> :</p>
  
  <pre><code> import Foundation
  
  class Data {
      static var userModels = [UserModel]()
      static var itemModels = [ItemModel]()
  }
  </code></pre>
  
  <p>I would update the data by doing something like this in my <code>views</code>:</p>
  
  <pre><code>let user = UserModel(name: "Bob")
  Data.userModels.append(user)
  </code></pre>
  
  <p>I'm having trouble populating a <code>List</code> from this framework in <code>SwiftUI</code>. I tried to make both of my model classes conform to <code>Identifiable</code> but that doesn't seem to help in updating the list. This is what I'm doing so far:</p>
  
  <p>Updated <code>UserModel</code> :</p>
  
  <pre><code>struct UserModel: Identifiable {
      var id = UUID()
  
      var name: String
      var items = [ItemModel]()
  
      init(id: UUID, name: String, items: [ItemModel]? = nil) {
          self.id = id
          self.name = name
          if let items = items {
              self.items = items
          }
      }
  }
  </code></pre>
  
  <p>Updated <code>ItemModel</code>:</p>
  
  <pre><code>struct ItemModel: Identifiable {
      var id = UUID()
  
      var itemName: String
      var price: Double
  
      init(id: UUID, itemName: String, price: Double) {
          self.id = id
          self.itemName = itemName
          self.price = price
      }
  }
  </code></pre>
  
  <p>And in my <code>ContentView.swift</code></p>
  
  <pre><code>List (Data.userModels) { user in
      Text("\(user.name)")
  
  }
  </code></pre>
  
  <p>But this does not update the <code>List</code> when I am running the app. (Btw I take input from <code>TextField</code>, append it to <code>Data.userModels</code>, and try to populate it in the <code>List</code> with no luck.)</p>
  
  <p>Is there a different way I should be structuring my data and data models? Or am I just not using the proper syntax when creating the list? Sorry for the long question. Thanks for the help!</p>