dimanche 27 septembre 2015

Swift 2.0 Reflection on Metatype

Swift reflection works great on an instance of a particular type but what if I want to print out all the instance variables of a particular class?

Creating a Mirror works for an instance:

Mirror(reflecting: self).children.filter { $0.label != nil }.map { return $0.label! }

but when self is a class like Bird or Fruit, the list returned is empty.





Aucun commentaire:

Enregistrer un commentaire