<code
class
=
"swift"
>protocol Conscious {
static
func awake()
}
extension UIViewController: Conscious {
static
func awake() {
if
self == UIViewController.self {
print
(self, #
function
)
}
}
}
private
static
let _operation: Void = {
let typeCount = Int(objc_getClassList(nil, 0))
let types = UnsafeMutablePointer<AnyClass?>.allocate(capacity: typeCount)
let autoreleasingTypes = AutoreleasingUnsafeMutablePointer<AnyClass?>(types)
objc_getClassList(autoreleasingTypes, Int32(typeCount))
for
index in 0 ..< typeCount {
(types[index]
as
? Conscious.Type)?.awake()
if
let t = types[index]
as
? Conscious.Type {
print
(t)
}
let T = types[index]!
let vc = UIViewController()
print
(T, vc.isKind(of: T), T == UIViewController.self)
}
types.deallocate(capacity: typeCount)
}()</code>