title: Passing a BindableObject to the views
body: <p>From the Apple's sessions and Tutorial we have two options to pass BindableObject to the views.</p>
  
  <ol>
  <li>Use declare <code>BindableObject</code> as a Source of truth in the top view in the hierarchy with <code>@ObjectBinding</code> wrapper and pass it to other views with <code>@Binding</code> declared.</li>
  <li>Use declare <code>BindableObject</code> as a Source of truth in the top view in the hierarchy with <code>@EnviromentObject</code> wrapper, init top view with <code>.enviroment(BindableObject)</code> modifier and pass it to other views or with <code>@Binding</code> declared, or using <code>@EnviromentObject</code>(in this case <code>BindableObject</code> will be assigned automatically by SwiftUI and we do not need to pass it on init).</li>
  </ol>
  
  <p>From <a href="https://developer.apple.com/tutorials/swiftui/handling-user-input" rel="nofollow noreferrer">Handling User Input tutorial</a> if we have <code>BindableObject</code> with list of items in and we want to change one of the items on other view(or RowView or even separate screen) we need to:</p>
  
  <ol>
  <li>Pass the <code>BindableObject</code> to the deeper view using any of the ways above.
  
  <ol start="2">
  <li>Pass the selected item to this view.</li>
  <li>Bind the property of the item with <code>BindingView</code> by finding the item in <code>BindableObject</code> list.</li>
  </ol></li>
  </ol>
  
  <p>Some code to make the question clear:</p>
  
  <p>Message model and <code>BindableObject</code></p>
  
  <pre><code>struct Message: Identifiable {
      var id: String
      var toggle: Bool = true
  }
  
  class MessageStore: BindableObject {
  
    let didChange = PassthroughSubject&lt;MessageStore, Never&gt;()
  
    var messagesList: [Message] = testData {
      didSet {
        didChange.send(self)
      }
    }
  }
  </code></pre>
  
  <p>MessageView that represents a list of items
  struct MessagesView</p>
  
  <pre><code> : View {
  
      @EnvironmentObject var messageStore: MessageStore
  
      var body: some View {
          NavigationView {
              List(messageStore.messagesList) { message in
                  NavigationButton(destination: Text(message.id)) {
                      MessageRow(message: message)
                  }
              }
              .navigationBarTitle(Text("Messages"))
          }
      }
  }
  </code></pre>
  
  <p>MessageRow that has a Toggle to update the state of particular item in out <code>BindableObject</code></p>
  
  <pre><code>struct MessageRow: View {
  
      @EnvironmentObject var tags: MessageStore
      var message: Message
  
      var messageIndex: Int {
          tags.messagesList.firstIndex { $0.id == message.id }!
      }
  
  
      var body: some View {
         Toggle(isOn: self.$tags.messagesList[self.messageIndex].toggle) {
             Text("Test toogle")
         }
      }
  
  }
  </code></pre>
  
  <p>This approach is shown in the tutorial I mentioned above.</p>
  
  <p><strong>Question:</strong>
  I wanted to pass Message separately as a <code>@Binding</code> to work with it in the child view directly, but I wasn't able to implement this.
  I became a bit confused. Is it proper way to pass to any view(that should handle bindings) both the <code>BindableObject</code> and selected item to bind later the item from <code>BindableObject</code> using index? Is there any other way that will allow to pass not a full <code>BindableObject</code> but a part of it and bind this part(it should be Source of truth), in our case this part is <code>Message</code>?</p>