Cut: copy: & paste: methods are never called

I’m trying to update the code to Xcode 9 & Swift 4. I’ve implemented the cut:, copy:, & paste: methods according to page 325. There are no compiler warnings or errors. When I run the program, I cannot use the Cut, Copy, or Paste commands. The menu commands are disabled and using the Command-key shortcuts fails. The MainMenu.xib shows the methods correctly connected to the first responder.

This is what the updated versions of the methods look like:

@IBAction func cut(sender: AnyObject?) {
    writeToPasteboard(pasteboard: NSPasteboard.general)
    intValue = nil
  }
  
  @IBAction func copy(sender: AnyObject?) {
    writeToPasteboard(pasteboard: NSPasteboard.general)
  }
  
  @IBAction func paste(sender: AnyObject) {
    _ = readFromPasteboard(pasteboard: NSPasteboard.general)
  }

Any one have any ideas about why my @IBAction methods are not getting hooked up correctly leaving the Cut/Copy/Paste commands unusable?

Here is the validateMenuItem(_:) that works in Xcode 9. See if it helps.

override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  guard let action = menuItem.action else {
    fatalError("Unexpected MenuItem configuration")
  }

  switch action {
  case #selector(cut(_:)), #selector(copy(_:)):
    return intValue != nil
  default:
    return true
  }
}

Thanks hkray. The book hadn’t got to talking about the validateMenuItem function yet so I hadn’t put it into the code. Once I did add it I got compiler errors telling me the selectors didn’t match any of my functions. This is because of the _ parameter your #selector statements used but I did not have in my code. Adding just the _ to the parameter lists for the cut/copy/paste functions got the methods working properly.