I am trying to use the long press button function but am not sure how to pass the tag of the button to the function. I have an array of buttons called ChannelButton. The long button press works with the code below.
for button in ChannelButton {
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(sender:)))
button.addGestureRecognizer(longPressGestureRecognizer)
}
func handleLongPress(sender: UILongPressGestureRecognizer) {
doSomeFunction(NeedToPassTheButtonsTagHere)
}
But I need it to modify it to be something like this
for button in ChannelButton {
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(sender:, button.tag)))
button.addGestureRecognizer(longPressGestureRecognizer)
}
func handleLongPress(sender: UILongPressGestureRecognizer, buttontag) {
doSomeFunction(buttontag)
}
I know this doesn't work but I'm not sure how to go about it.