如何将addTarget方法更新为swift 4

Hab*_*lil 3 xcode selector ios swift swift4

当更新项目代码到swift 4得到add.target方法的一些错误我怎么能修复这个错误?

 //swift3

var chatLogController: ChatLogController? {
    didSet {
        sendButton.addTarget(chatLogController, action: #selector(ChatLogController.handleSend), for: .touchUpInside)

       uploadImageView.addGestureRecognizer(UITapGestureRecognizer(target: chatLogController, action: #selector(ChatLogController.handleUploadTap)))
    }
}
Run Code Online (Sandbox Code Playgroud)

Ras*_*n L 9

提示消息告诉您该怎么做,@obj在声明您的功能之前添加.

@objc func handleSend(_ sender: UIGestureRecognizer){
    ...
}
Run Code Online (Sandbox Code Playgroud)

原因是因为:

在Objective-C中,选择器是一种引用Objective-C方法名称的类型.在Swift中,Objective-C选择器由Selector结构表示,并且可以使用#selector 表达式构造.要为可以从Objective-C调用的方法创建选择器,请传递方法的名称,例如 #selector(MyViewController.tappedButton(_:)).要为属性的Objective-C getter或setter方法构造选择器,请传递以getter:or setter:标签为前缀的属性名称,例如 #selector(getter: MyViewController.myButton).

更多在这里,在苹果的文档.