title: Pass data from one ViewModel to another in SwiftUI?
body: <p>I have a ViewModel <code>VM_App</code> with a list of names, with another View <code>V_NamesList</code> inside <code>V_App</code> that is supposed to display these names. For that, I am passing the list from <code>VM_App</code> to <code>VM_NamesList</code>, but the View gets redrawn while editing the names.</p>
  <p>VM_App</p>
  <pre><code>class VM_App: ObservableObject {
      @Published var names: [String] = [
          &quot;Tobias&quot;,
          &quot;Jonathan&quot;,
          &quot;&quot;
      ]
  }
  </code></pre>
  <p>V_App</p>
  <pre><code>struct V_App: View {
      @ObservedObject var vm: VM_App = VM_App()
  
      var body: some View {
          VStack {
              V_NamesList(
                  VM_NamesList(names: $vm.names)
              )
          }
      }
  }
  </code></pre>
  <p>VM_NamesList</p>
  <pre><code>class VM_NamesList: ObservableObject {
      @Binding var names: [String]
      
      init(names: Binding&lt;[String]&gt;) {
          self._names = names
      }
  }
  </code></pre>
  <p>V_NamesList</p>
  <pre><code>struct V_NamesList: View {
      @ObservedObject var vm: VM_NamesList
      
      init(_ vm: VM_NamesList) {
          self.vm = vm
      }
      
      var body: some View {
          ForEach(Array(vm.names.enumerated()), id: \.element) { (i, name) in
              TextField(&quot;New Player&quot;, text: $vm.names[i])
          }
      }
  }
  </code></pre>