Passar argumento extra para UItapgestureRecognizer com seletor
Eu tenho dois rótulos, Label1 e Label2. Quero criar uma única função que imprima qual rótulo é tocado, criando UITTapRecognizer para os dois rótulos que chamam a mesma função com o seletor que passa um argumento. Abaixo está o longo caminho de fazê-lo, que é confuso, mas funciona. Se eu sei como passar um argumento (Int) para o seletor, seria muito mais limpo.
let topCommentLbl1Tap = UITapGestureRecognizer(target: self, action: #selector(DiscoverCell().doubleTapTopComment1))
topCommentLbl1Tap.numberOfTapsRequired = 2
topCommentLbl1.userInteractionEnabled = true
topCommentLbl1.addGestureRecognizer(topCommentLbl1Tap)
let topCommentLbl2Tap = UITapGestureRecognizer(target: self, action: #selector(DiscoverCell().doubleTapTopComment2))
topCommentLbl2Tap.numberOfTapsRequired = 2
topCommentLbl2.userInteractionEnabled = true
topCommentLbl2.addGestureRecognizer(topCommentLbl2Tap)
func doubleTapTopComment1() {
print("Double Tapped Top Comment 1")
}
func doubleTapTopComment2() {
print("Double Tapped Top Comment 2")
}
Existe uma maneira de modificar o método seletor para que eu possa fazer algo como
func doubleTapTopComment(label:Int) {
if label == 1 {
print("label \(label) double tapped")
}