我想用Objective-C运行时函数获取所有已知类的列表:

var count = UInt32(0)
let classList = objc_copyClassList(&count)

objc_copyClassList()返回类似3900的值。countclassList类型的对象。
我如何遍历AutoreleasingUnsafeMutablePointer<Optional<AnyObject.Type>>以获得所有这些带有classList的3900个类的名称?

最佳答案

好吧,我自己想出来了:

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)
}

关于swift - 推迟自动释放UnsafeMutablePointer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37266264/

10-13 02:32