title: How do I declare a variable that has a type and implements a protocol?
body: <p>My app has a protocol for detail view controllers, stating they must have a <code>viewModel</code> property:</p>
  
  <pre><code>protocol DetailViewController: class {
      var viewModel: ViewModel? {get set}
  }
  </code></pre>
  
  <p>I also have a few different classes that implement the protocol:</p>
  
  <pre><code>class FormViewController: UITableViewController, DetailViewController {
      // ...
  }
  
  class MapViewController: UIViewController, DetailViewController {
      // ...
  }
  </code></pre>
  
  <p>My master view controller needs a property that can be set to any <code>UIViewController</code> subclass that implements the <code>DetailViewController</code> protocol.</p>
  
  <p>Unfortunately I can't find any documentation on how to do this. In Objective-C it would be trivial:</p>
  
  <pre><code>@property (strong, nonatomic) UIViewController&lt;DetailViewController&gt;;
  </code></pre>
  
  <p>It appears that there isn't any syntax available in Swift to do this. The closest I've come is to declare a generic in my class definition:</p>
  
  <pre><code>class MasterViewController&lt;T where T:UIViewController, T:DetailViewController&gt;: UITableViewController {
      var detailViewController: T?
      // ...
  }
  </code></pre>
  
  <p>But then I get an error saying that "Class 'MasterViewController' does not implement its superclass's required members"</p>
  
  <p>This seems like it should be as easy to do in Swift as it is in Objective-C, but I can't find anything anywhere that suggests how I might go about it. </p>