After confirming to some iOS Developers, no you can't do this yet.
But there is an alternative. You can receive the sender object in the action method. You can add any property to the sender class. And receive that in action method.
for example:
First approach
let button = UIBarButtonItem(title: "Run",
style: .Plain,
target: self,
action: #selector(run(_:)))
button.tag = 1
And you can receive it like this
func run(sender: UIBarButtonItem) {
let passedInteger = sender.tag
}
But it only work if the passed parameter is a single Integer. Here's how you can do it if you want to pass multiple parameter with any data type -> Look at Second Approach
Second Approach
Subclass UIBarButtonItem
class MyBarButtonItem: UIBarButtonItem {
var passedParameter: String?
}
And receive it like this
let button = MyBarButtonItem(title: "Run",
style: .Plain,
target: self,
action: #selector(run(sender:)))
button.passedParameter = "John Doe"
func run(sender: MyBarButtonItem) {
// now you have the parameter
let parameter = sender.passedParameter
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…