同一个参数有两个不同的名称有什么意义? [英] What is the point of having two different names for the same parameter?

查看:17
本文介绍了同一个参数有两个不同的名称有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

func mapEachElement (inArray arr: [Int],  withFunc aFunc: (Int))

为什么会有inArray"然后是arr"...有什么意义?

Why would there be "inArray and then "arr"...what's the point?

withFunc"和aFunc"也是一样,代码更复杂,读起来也更乱,为什么要使用它们?

Same for "withFunc and "aFunc", it makes it more code complicated and also messier to read, why are they even used?

推荐答案

inArray 是函数的调用者在传递参数时应该使用的外部名称.arr 是函数实现者在实现中用来引用参数的内部名称.您不必提供外部名称.它使其更具可读性.更像是让 swift 函数名和参数像 Objective-C 函数一样可读.

inArray is external name which the caller of the function should use when passing parameters. arr is the internal name which the function implementer uses in the implementation to refer to the parameter. You don't have to supply external name.It makes it more readable. It is more like to make swift function names and parameters readable as Objective-C functions are.

这篇关于同一个参数有两个不同的名称有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆