Swift 2.0 Get Mirrored Superclass Properties

后端 未结 6 1831
盖世英雄少女心
盖世英雄少女心 2020-12-20 16:16

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:

protocol ListsP         


        
6条回答
  •  情书的邮戳
    2020-12-20 16:52

    You can simply loop through all the superclassMirrors get the properties. It doesn't matter how many layers there are.

    var mirror: Mirror? = Mirror(reflecting: child) repeat { for property in mirror!.children { print("property: \(property)") } mirror = mirror?.superclassMirror() } while mirror != nil

提交回复
热议问题