touchesBegan(触摸:NSSet,withEvent事件:UIEvent)
这一行中“withEvent”关键字的功能是什么?
我找不到关于“withEvent”一般做什么或这些类型的函数参数修饰符可能做什么、如何定义它们或它们有多少的文档。
最佳答案
这是一个外部参数名称。来自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
这意味着在函数体内,您通过 event
引用该参数,但是任何调用您的函数的人都将使用 withEvent
作为参数名称。
关于ios - Swift中 "withEvent"的含义,以及一般的参数修饰符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27759588/