title: Swift Protocol Extension Where Self Is Subclass
body: <p>Is it possible to implement a protocol or protocol extension that specifies that the protocol will only be used for classes &amp; that those classes have super classes ?</p>
  
  <p>If so, can I leverage this to have a function that iterates down through a class's superclasses to gather all of the data they each is storing one common variable ?</p>
  
  <p>In other words, in the example below is it possible to create an extension that does what the second BaseType extension pseudocode is trying to do such that at the end <code>allVals = ["core", "middle", "top"]</code> ?</p>
  
  <pre><code>import Foundation
  
  protocol BaseType: class {
    var data: [String] { get }
    var all: [String] { get }
  }
  
  extension BaseType {
    var all: [String] {
      return data
    }
  }
  
  // Is the intent of this extension realistic? 
  extension BaseType where Self.super is BaseType {
    var all: [String] {
      return data + super.all
    }
  }
  
  class CoreDT: BaseType {
    var core: String = "core"
    var data: [String] { return [core] }
  }
  
  
  class MiddleDT: CoreDT {
    var middle: String = "middle"
    override var data: [String] { return [middle] }
  }
  
  class TopDT: MiddleDT {
    var top: String = "top"
    override var data: [String] { return [top] }
  }
  
  let allVals = TopDT().all
  
  print(allVals)
  </code></pre>