"withEvent"的含义是:在Swift中,通常使用参数修饰符 [英] The meaning of "withEvent" in Swift, and parameter modifiers in general
问题描述
touchesBegan(touches:NSSet,withEvent事件:UIEvent)
touchesBegan(touches: NSSet, withEvent event: UIEvent)
此行中"withEvent"关键字的功能是什么?
What is the "withEvent" keyword's functionality in this line?
我找不到有关"withEvent"的一般功能或这些函数参数修饰符的作用,如何定义它们或有多少个的文档.
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.
推荐答案
这是一个外部参数名称.从关于功能的Swift文档:>
That's an external parameter name. From the Swift documentation on functions:
外部参数名称
有时,在调用函数时命名每个参数很有用,以指示传递给函数的每个参数的用途.
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
这意味着在函数体内,您可以通过event
引用该参数,但是任何调用您函数的人都将使用withEvent
作为参数名称.
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.
这篇关于"withEvent"的含义是:在Swift中,通常使用参数修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!