Swift 2.0 Get Mirrored Superclass Properties

后端 未结 6 1827
盖世英雄少女心
盖世英雄少女心 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 17:00

    My solution is to use

    Mirror(self, children: properties, ancestorRepresentation: Mirror.AncestorRepresentation.generated)
    

    Instead of

    Mirror(representing: self)
    

    properties is a DictionnaryLiteral object containing the properties I want to be mirrored.

提交回复
热议问题