The meaning of “withEvent” in Swift, and parameter modifiers in general

后端 未结 1 1951
长情又很酷
长情又很酷 2021-01-28 11:17

touchesBegan(touches: NSSet, withEvent event: UIEvent)

What is the \"withEvent\" keyword\'s functionality in this line?

I couldn\'t find documentation on what \"

相关标签:
1条回答
  • 2021-01-28 11:51

    That's an external parameter name. From the Swift documentation on functions:

    External Parameter Names

    Sometimes it’s useful to name each parameter when you call a function, to indicate the purpose of each argument you pass to the function.

    If you want users of your function to provide parameter names when they call your function, define an external parameter name for each parameter, in addition to the local parameter name. You write an external parameter name before the local parameter name it supports, separated by a space

    This means that inside the body of the function, you refer to that parameter by event, but anyone calling your function will use withEvent as the parameter name instead.

    0 讨论(0)
提交回复
热议问题