Selector vs Action Swift 4

Viewed 20330

New to Swift. I have two snippets below:

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"]!)")

}

and finally

let x:UITapGestureRecognizer = UITapGestureRecognizer(target: self, 
    action: #selector(tapped))

self.addGestureRecognizer(x)

func tapped(){
    print("tapped")

    self.delegate!.theViewTapped()

}

Why is it that for the notificationCenter? I am supposed to provide the @objc tag for the selector parameter but not for the UITapGestureRecognizer action parameter?

What exactly is the difference between Selector and Action in Swift?

1 Answers
Related