title: Is ti possible to `map` an enum to Binding<Bool> in SwiftUI?
body: <p>Working with <code>MVVM</code> in SwifUI. My aim is to have an <code>enum</code> state property in the <code>ViewModel</code> so the <code>View</code> could adjust it self according to the state property. States could be: <code>idle</code>, <code>busy</code>, <code>done</code> and <code>error</code>. On <code>done</code> I want to navigate to another screen using <code>NavigationLink</code>, however the problem is that it is expecting a <code>Binding&lt;Bool&gt;</code> and I could not figure out a way to map my enum state to bool.</p>
  
  <p>Here is the simplified code:</p>
  
  <pre><code>struct LoginView: View {
  
      @ObservedObject private var viewModel: LoginViewModel
  
      @ViewBuilder
      var body: some View {
          ...
          // success state
          NavigationLink(destination: HomeFactory().make(), isActive: self.$viewModel.state /* &lt;---- some sort of mapping should come here */){ EmptyView() }
          ...
      }
  }
  </code></pre>
  
  <p>Hope that I am missing something really basic and it could be easily achieved in an elegant way.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Seems like it should be possible with the next method:<br/>
  <code>NavigationLink(destination: HomeFactory().make(), tag: .done, selection: self.$viewModel.viewState, label: { EmptyView() })</code></p>
  
  <p>However I get an error and I can't figure out what is wrong: <code>Cannot convert value of type 'Binding&lt;ViewState&gt;' to expected argument type 'Binding&lt;_?&gt;'</code></p>
  
  <p>Here is the code:</p>
  
  <pre><code>final class LoginViewModel: ObservableObject {
    @Published var viewState: ViewState = .idle
    func begin() {
      ..
      self.viewState = .done
      ..
    }
  }
  
  struct LoginView: View {
    @ObservedObject private var viewModel: LoginViewModel
  
    @ViewBuilder
    var body: some View {
      ..
      NavigationLink(destination: HomeFactory().make(), tag: .done, selection: self.$viewModel.viewState, label: { EmptyView() })
      ..
    }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I was very close. The <code>ViewState</code> in the vm should be optional:<br/>
  <code>@Published var viewState: ViewState? = .idle</code></p>