0
votes

touchesBegan(touches: NSSet, withEvent event: UIEvent)

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

I couldn't find documentation on what "withEvent" does in general or what these sort of function parameter modifiers might do, how to define them, or how many of them there are.

1

1 Answers

1
votes

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.