So, let's say I have a class like this:
class Employee: NSObject { var id: String? var someArray: [Employee]? }
I use reflection to get property names:
let employee = Employee() let mirror = Mirror(reflecting: employee) propertyNames = mirror.children.flatMap { $0.label } // ["businessUnitId", "someArray"]
so good so far! Now I need to find out the type of each of these properties, so if I do employee.valueForKey("someArray") , this will not work, because it gives me only the AnyObject type. What would be the best way to do this? Especially for the array, I need to be able to dynamically report that the array contains an Employee type.
source share