title: Deriving binding from existing SwiftUI @States
body: <p>I've been playing around with SwiftUI and Combine and feel like there is probably a way to get a hold of the existing @State properties in a view and create a new one.</p>
  
  <p>For example, I have a password creation View which holds a password and a passwordConfirm field for the user. I want to take those two @State properties and derive a new @State that I can use in my view that asserts if the input is valid. So for simplicity: not empty and equal.</p>
  
  <p>The Apple docs say <a href="https://developer.apple.com/documentation/swiftui/binding/3264174-publisher" rel="noreferrer">there is a publisher</a> on a binding, though I can't appear to get ahold of it.</p>
  
  <p>This is some non-functioning pseudo code:</p>
  
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  import Combine
  
  struct CreatePasswordView : View {
      @State var password = ""
      @State var confirmation = ""
      lazy var valid = {
          return self.$password.publisher()
              .combineLatest(self.$confirmation)
              .map { $0 != "" &amp;&amp; $0 == $1 }
      }
  
      var body: some View {
          SecureField($password, placeholder: Text("password"))
  
          SecureField($confirmation, placeholder: Text("confirm password"))
  
          NavigationButton(destination: NextView()) { Text("Done") }
              .disabled(!valid)
      }
  }
  </code></pre>
  
  <p>Anyone found. the appropriate way of going about this / if it's possible?</p>
  
  <p>UPDATE Beta 2:</p>
  
  <p>As of beta 2 publisher is available so the first half of this code now works. The second half of using the resulting publisher within the View I've still not figured out (<code>disabled(!valid)</code>).</p>
  
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  import Combine
  
  struct CreatePasswordView : View {
      @State var password = ""
      @State var confirmation = ""
  
      lazy var valid = {
          Publishers.CombineLatest(
              password.publisher(),
              confirmation.publisher(),
              transform: { String($0) != "" &amp;&amp; $0 == $1 }
          )
      }()
  
      var body: some View {
          SecureField($password, placeholder: Text("password"))
  
          SecureField($confirmation, placeholder: Text("confirm password"))
  
          NavigationButton(destination: NextView()) { Text("Done") }
              .disabled(!valid)
      }
  }
  </code></pre>
  
  <p>Thanks.</p>