Why do I need underscores in swift?

后端 未结 4 626
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 16:51

Here it says, \"Note: the _ means “I don’t care about that value”\", but coming from JavaScript, I don\'t understand what that means.

The only way I can

4条回答
  •  执笔经年
    2020-11-30 17:11

    Since Swift 3, specifying parameter names on function calls has become compulsory - even for the first. So, because that could cause huge problem to code written in swift 2, you can use a underscore at the declaration to prevent having to write the parameter name on call. So in this case, it is saying "don't care about the external parameter name". Where the external parameter name is what you call the parameters outside the function (on call) not inside. These external parameter names are called argument labels. http://ericasadun.com/2016/02/09/the-trouble-with-argument-labels-some-thoughts/ ... see how the parameter is given two names? well the first is where the underscore is going.Hope this helps, and do ask if still confused.

提交回复
热议问题