title: Swift 2.0 Get Mirrored Superclass Properties
body: <p>I need to get the properties of my class as a dictionary. For simplicity, I created a protocol which has a default implementation as follows:</p>
  
  <pre><code>protocol ListsProperties{
      func toDictionary() -&gt; [String: AnyObject]
  }
  
  extension ListsProperties{
      func toDictionary() -&gt; [String: AnyObject] {
          let mirrored_object = Mirror(reflecting: self)
          var dict = [String: AnyObject]()
          for (_, attr) in mirrored_object.children.enumerate() {
              if let propertyName = attr.label as String! {
                  dict[propertyName] = attr.value as? AnyObject
              }
          }     
  
          return dict
      }
  }
  </code></pre>
  
  <p>My classes can conform to this protocol and will have the toDictionary() method available. However, this does not work if I use the method on a subclass, as it will produce only the properties defined on the subclass and ignore the parent superclass properties.</p>
  
  <p>Ideally I could find some way to call the toDictionary() method on the mirrored superclass as this would then call toDictionary() on its own superclass and the compiler says that the superclass mirror does not conform to the Protocol even though the class it is mirroring does.</p>
  
  <p>The following works but only if there is only one superclass so isn't sufficient:</p>
  
  <pre><code>func toDictionary() -&gt; [String: AnyObject] {
      let mirrored_object = Mirror(reflecting: self)
      var dict = [String: AnyObject]()
      for (_, attr) in mirrored_object.children.enumerate() {
          if let propertyName = attr.label as String! {
              dict[propertyName] = attr.value as? AnyObject
          }
      }
  
      // This is an issue as it limits to one subclass 'deep' 
      if let parent = mirrored_object.superclassMirror(){
          for (_, attr) in parent.children.enumerate() {
              if let propertyName = attr.label as String!{
                  if dict[propertyName] == nil{
                      dict[propertyName] = attr.value as? AnyObject
                  }
              }
          }
      }
  
      return dict
  }
  </code></pre>
  
  <p>Any ideas on how I could modify the default implementation of toDictionary() to include superclass attributes (and the attributes of any superclasses of the superclass etc)?</p>