gpt4 book ai didi

ios - objc_copyClassList : crash EXC_BAD_INSTRUCTION after update to iOS 13. 4/XCode 11.4

转载 作者:行者123 更新时间:2023-12-01 15:31:31 30 4
gpt4 key购买 nike

更新到 iOS 13.4/XCode 11.4 后

这段代码

func getSubclassInfos() -> [ClassInfo] {
let superObject = CityModel.self
let superClassInfo = ClassInfo(superObject)

var subclassList = [ClassInfo]()
var count = UInt32(0)
guard let classList = objc_copyClassList(&count) else {
return subclassList
}
for i in 0..<Int(count) {
let clazz = classList[i] // Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
if let classInfo = ClassInfo(classList[i]),
let superclassInfo = classInfo.superclassInfo,
superclassInfo == superClassInfo
{
subclassList.append(classInfo)
}
}

return subclassList
}

在线崩溃 let clazz = classList[i]EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)在模拟器中。

这行不在我的原始代码中。在这里显示下标崩溃而不是 ClassInfo(...)
知道我能做些什么吗?

(代码的灵感来自 List all subclasses of one class )

最佳答案

刚注意到:classList完全是用词不当。返回的结果类型为 AutoreleasingUnsafeMutablePointer<AnyClass>? .将其转换为 UnsafeBufferPointer<AnyClass>首先,然后进行处理:

func getSubclassInfos() -> [ClassInfo] {
let superObject = CityModel.self
let superClassInfo = ClassInfo(superObject)

var count = UInt32(0)
guard let classListPointer = objc_copyClassList(&count) else { return [] }

return UnsafeBufferPointer(start: classListPointer, count: Int(count))
.map(ClassInfo.init)
.filter { $0 == superClassInfo }
}

关于ios - objc_copyClassList : crash EXC_BAD_INSTRUCTION after update to iOS 13. 4/XCode 11.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60853427/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com