我正在尝试将一些 Objective-C 代码转换为 Swift 代码。
我如何转换它,因为我在 swift 中找不到任何等价物。
((void (*)(id, SEL, id, id))objc_msgSend)(anObject, mySelector, anotherObject, lastObject)
最佳答案
swift 3.1
let handle : UnsafeMutableRawPointer! = dlopen("/usr/lib/libobjc.A.dylib", RTLD_NOW)
unsafeBitCast(dlsym(handle, "objc_msgSend"), to:(@convention(c)(Any?,Selector!,Any?,Any?)->Void).self)(anObject,#selector(mySelector),anotherObject,lastObject)
dlclose(handle)
您也可以使用 class_getMethodImplementation
unsafeBitCast(class_getMethodImplementation(type(of: anObject), #selector(mySelector)), to:(@convention(c)(Any?,Selector!,Any?,Any?)->Void).self)(anObject,#selector(mySelector), anotherObject,lastObject)
关于ios - 将 objective-c 调用转换为 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28479445/