0

Suppose I have the following function:

 @objc func action(_ gesture : UITapGestureRecognizer){}

Now to call the function, we usually use a syntax like so:

let mygesture = UITapGestureRecognizer(target: self, action: #selector(action(_:)))

What does the syntax action(_:) actually mean? How are we passing the value of the input parameter gesture required by the function? Doesn't it has to be something like action(_: somevalue)

From my guess, we are only providing the access to the function by writing action(_:). And the function is actually called by passing the mygesture variable itself when the tap gesture is triggered. Is that correct?

Asha
  • 41
  • 5
  • This is part of the "Target-Action" mechanism. You can read [more about it here](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Target-Action/Target-Action.html) (last paragraph for UIKit). – Alladinian Aug 25 '20 at 13:29
  • https://stackoverflow.com/a/24007718/1630618 – vacawama Aug 25 '20 at 14:20
  • Thanks a lot guys! Appreciate your help – Asha Aug 25 '20 at 17:54

1 Answers1

1

You're right. You're passing the pointer of the function to the gesture recognizer.