我想用Objective-C运行时函数objc_copyClassList()
获取所有已知类的列表:
var count = UInt32(0)
let classList = objc_copyClassList(&count)
count
返回类似3900的内容。classList
是AutoreleasingUnsafeMutablePointer<Optional<AnyObject.Type>>
类型的对象。
如何遍历classList
以获取class_getName()
所有3900个班级的名称?
答案 0 :(得分:1)
好的,我自己弄清楚了:
var count = UInt32(0)
let classList = objc_copyClassList(&count)
for i in 0..<Int(count) {
let cName = class_getName(classList[i])
let classname = NSString(CString: cName, encoding: NSUTF8StringEncoding)!
print(className)
}