从变量分配 UIButton 目标

Assign UIButton target from variable

是否可以从变量分配目标?我有一个函数可以添加和删除一个非常多余的目标,我想将它截断一点。我创建了一个 typealias,它复制了 UIButtonTarget 预期的参数,但没有参数就无法分配目标。错误: 调用中缺少参数 'action' 的参数

 @IBAction func didTapActionBtn(sender: UIButton){
    typealias btnTarget = (_: AnyObject?, action: Selector, for: UIControlEvents)
    let prevTarget: btnTarget = (self, action: #selector(self.showPrevApp), for: .touchUpInside)

    if sender.tag == 0{
      sender.tag = 1
      prevBtn.removeTarget(prevTarget) //*Missing argument for parameter 'action' in call
      nextBtn.removeTarget(self, action: #selector(self.showNextApp), for: .touchUpInside)
    }else{
      sender.tag = 0
      prevBtn.addTarget(self, action: #selector(self.showPrevApp), for: .touchUpInside)
      nextBtn.addTarget(self, action: #selector(self.showNextApp), for: .touchUpInside)
    }
  }

您尝试执行的操作(隐式元组展开行为)曾经在 Swift 中有效,但在 Swift 2.2 中已弃用并被删除在 Swift 3.

这是 Swift 2.2 错误消息:

Passing 3 arguments to a callee as a single tuple value is deprecated

有关删除元组 splat 行为的动机,请参阅以下内容:

SE-0029 Remove Implicit Tuple Splat Behavior