Reflection in Swft
Reflection allows you to inspect the internal structure of types at run time. For example it is useful for testing private members of class.
In Swift a reflection is implemented through Mirror API.
let mirror = Mirror(reflecting: targetObject)
// some members can other inner name, for example,
// "$__lazy_storage_$_tableView" for "lazy var tableView: UITableView = ..."
for child in mirror.children {
print("Property name:", child.label)
print("Property value:", child.value)
}
Mirror API allows to handle properties of specified type.
Mirror.reflectProperties(of: targetObject) {
(child: Preloadable) in
// ... do something with child
}