尝试调用长按手势和 运行 命令,但 运行 与函数中的选择器一起进入 SIGABRT 错误。什么没有连接?

Trying to call a long tap gesture and run a command but running into a SIGABRT error with the selector in the function. What isn't connected?

我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    //Adding the long gesture
    let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longTap))

    //Adding the gesture to the button
    hydrogenBoxButton.addGestureRecognizer(longGesture)

    //Adding a tag for the button
    hydrogenBoxButton.tag = 1
}

然后在选择器中调用我的函数:

 @objc func longTap(sender: UIButton) {

        if sender.tag == 1 {
            print("Hydrogen long tap worked!")
        } else if sender.tag == 2 {
            print("Helium long tap worked!")
        }
    }

但是,当我 运行 尝试长按按钮时,我得到了这个错误:

-[UILongPressGestureRecognizer tag]: unrecognized selector sent to instance 0x7fbc5ce00680

我不知道是因为我给标签命名错误还是我创建 LongPressGestureRecognizer 的方式有问题。

参数类型为UILongPressGestureRecognizer

@objc func longTap(sender: UILongPressGestureRecognizer ) {
        let tag = sender.view!.tag
        if tag == 1 {
            print("Hydrogen long tap worked!")
        } else if tag == 2 {
            print("Helium long tap worked!")
        }
}