title: How to define a protocol as a type for a @ObservedObject property?
body: <p>I have a swiftui view that depends on a view model, the view model has some published properties. I want define a protocol and default implementation for the view model hierarchy, and make the view dependent on the protocol not the concrete class?</p>
  
  <p>I want to be able to write the following:</p>
  
  <pre><code>protocol ItemViewModel: ObservableObject {
      @Published var title: String
  
      func save()
      func delete()
  }
  
  extension ItemViewModel {
      @Published var title = "Some default Title"
  
      func save() {
          // some default behaviour
      }
  
      func delete() {
          // some default behaviour
      }
  }
  
  
  struct ItemView: View {
      @ObservedObject var viewModel: ItemViewModel
  
      var body: some View {
          TextField($viewModel.title, text: "Item Title")
          Button("Save") { self.viewModel.save() }  
      }
  }
  
  // What I have now is this:
  
  class AbstractItemViewModel: ObservableObject {
      @Published var title = "Some default Title"
  
      func save() {
          // some default behaviour
      }
  
      func delete() {
          // some default behaviour
      }
  }
  
  class TestItemViewModel: AbstractItemViewModel {
      func delete() {
          // some custom behaviour
      }
  }
  
  struct ItemView: View {
      @ObservedObject var viewModel: AbstractItemViewModel
  
      var body: some View {
          TextField($viewModel.title, text: "Item Title")
          Button("Save") { self.viewModel.save() } 
      }
  }
  </code></pre>