如何在按钮目标选择器中放置变量

How to place variables inside button target selector

我有一个添加目标的按钮,选择器包含一个变量。
我可以在不收到错误的情况下将变量添加到选择器吗?
提前谢谢你。

//this cause a selector error when run
self.save.addTarget(self, action: #selector(self.saveItems(dataToSave)), forControlEvents: .TouchUpInside)

创建一个附加函数以将其用作操作 selector 参数

func helperFunc() {
    self.saveItems(dataToSave)
}

然后添加

self.save.addTarget(self, action: #selector(self.helperFunc), forControlEvents: .TouchUpInside)