ios - Swift中 "withEvent"的含义,以及一般的参数修饰符

标签 ios swift

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/

相关文章:

Swift 3 setValuesForKeys 错误

ios - 是否需要在头文件中声明辅助方法

iphone - 在启动时自动实例化单例

ios - 展开/折叠 UITableView 中的单元格数组

ios - 从 Swift 中的类实例获取类型

ios - 带有日期选择器的文本字段在日期快速更改时崩溃

ios - NavigationBar Hide on Swipe 后,Cells 出现在 HeaderCell 和 Status Bar 之间一秒钟

swift - 在 swift 框架中测试内部类

swift - 在没有 Storyboard的情况下使用 UITableView

ios - Swift:如何根据游戏状态制作 UISwitch 按钮作为设置?