简体   繁体   中英

Understanding Tapgesture syntax - Swift

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM