ios - 将 objective-c 调用转换为 swift

标签 ios swift

我正在尝试将一些 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/

相关文章:

ios - 从 SQLite 检索列到 TableView Swift iOS 单元格中的标签

ios - 更改播放按钮以暂停点击

ios - 如何将按钮设置为可用视口(viewport)高度的一半?

swift - 您可以在 Swift 中为特定的泛型类型进行协议(protocol)扩展吗?

ios - 如何从 SpriteKit 框架的 SKPhysicsBody 获取六边形形状

Swift UiButton 如何左对齐标题?

IOS Bug,键盘不显示

ios - 如何通过 AFNetworking 上传文件并发布多个参数?

iphone - UISearchBar:单击时如何停止调整大小?

ios - UIWebView 获取SPA(单页应用)网站的当前URL