スウィフトの新機能。それはnotificationCenter
のためにということですなぜセレクター対アクションスウィフト4
NotificationCenter.default.addObserver(self,
selector:#selector(ViewController.notificationReceived),
name: Notification.Name(rawValue: name), object: nil)
@objc func notificationReceived(notification:Notification){
let x = notification.userInfo!
print("\(x["name"]!)")
}
し、最終的に
let x:UITapGestureRecognizer = UITapGestureRecognizer(target: self,
action: #selector(tapped))
self.addGestureRecognizer(x)
func tapped(){
print("tapped")
self.delegate!.theViewTapped()
}
:私は下の2つのスニペットがありますか? selector
パラメータには@objc
タグを指定しますが、UITapGestureRecognizer
アクションパラメータには指定しないでください。
Selector
とAction in
スイフトの違いは何ですか?
の比較[Swift 4の#selector()で@objcの推論を非難するにはどうすればいいですか?](https://stackoverflow.com/q/44390378/2976878) - OOPerによると、両方の例ではターゲットメソッドは '@ objc'になります。 – Hamish