2

I have a problem with Xcode 11.4 using Swift 5.2 when trying to get value of func when performing a selector. This just occurred with a function that returns a Number or Bool type. That is my code:

if returnReadableType == "NSInteger" {
    let c: NSObject.Type = cls as! NSObject.Type
    if let performValue = c.perform(originalSelector)?.toOpaque() {
        let originalResponse: Int = Int(bitPattern: performValue)
        configDataResult[name] = originalResponse
    }
} else if returnReadableType == "BOOL" {
    let c: NSObject.Type = cls as! NSObject.Type
    if let performValue = c.perform(originalSelector)?.toOpaque() {
        let originalResponse: Bool = Bool(truncating: Int(bitPattern: performValue) as NSNumber)
        configDataResult[name] = originalResponse
    }
}

To explain the code, I try to perform an selector to get the value of it for swizzling them in the runtime. Because I don't know how much computed properties in a class will be declared, so I used the class_copyMethodList method to get all the method in cls. Then using some trick to determine the return type - returnReadableType, (in string) of each method. With the returnReadableType are BOOL or NSInteger, I got a crash when performed the selector. The crash log is:

Message from debugger: The LLDB RPC server has crashed. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.

This did not occur in the < Xcode 11.4. I have researched the issue but do not reach any solution or any problem like that. Have anyone got the same issue? And how I can solve this issue?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Perhaps an alternative to `performSelector` is an option? You could explicitly type the return value using `@convention(c)`. Check my answer here https://stackoverflow.com/a/43714950/5329717 – Kamil.S Mar 30 '20 at 19:42

0 Answers0