title: Swift -- Require classes implementing protocol to be subclasses of a certain class
body: <p>I'm creating several <code>NSView</code> classes, all of which support a special operation, which we'll call <code>transmogrify</code>.  At first glance, this seems like the perfect place for a protocol:</p>
  
  <pre><code>protocol TransmogrifiableView {
      func transmogrify()
  }
  </code></pre>
  
  <p>However, this protocol does <em>not</em> enforce that every <code>TransmogrifiableView</code> be an <code>NSView</code> as well.  This means that any <code>NSView</code> methods I call on a <code>TransmogrifiableView</code> will not type check:</p>
  
  <pre><code>let myView: TransmogrifiableView = getTransmogrifiableView()
  let theSuperView = myView.superView // error: TransmogrifiableView does not have a property called 'superview'
  </code></pre>
  
  <p>I don't know how to require that all classes implementing my protocol are also subclasses of <code>NSView</code>.  I tried this:</p>
  
  <pre><code>protocol TransmogrifiableView: NSView {
      func transmogrify()
  }
  </code></pre>
  
  <p>but Swift complains that protocols cannot inherit from classes.  It does not help to turn the protocol into a class-only protocol using</p>
  
  <pre><code>protocol TransmogrifiableView: class, NSView {
      func transmogrify()
  }
  </code></pre>
  
  <p><strong>I cannot make <code>TransmogrifiableView</code> a superclass rather than a protocol, because some of my <code>TransmogrifiableView</code> classes must be subclasses of other, non-transmogrifiable views.</strong></p>
  
  <p>How should I require that all <code>TransmogrifiableView</code>'s also be <code>NSView</code>'s?  I really don't want to pepper my code with "<code>as</code>" conversions, which are bad form and distracting.</p>