What is the point of having two different names for the same parameter?

后端 未结 3 1285
情深已故
情深已故 2020-11-30 14:50
func mapEachElement (inArray arr: [Int],  withFunc aFunc: (Int))

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

Same f

3条回答
  •  一生所求
    2020-11-30 15:31

    These are internal and external parameter names.

    Just like in Obj-C, you might have

    - (void)calculateFoo:(id)foo withBar:(id)bar ...
    
    [object calculateFoo:var1 withBar:var2];
    

    in Swift, we use

    func calculateFoo(foo: AnyObject, withBar bar: AnyObject) ...
    
    object.calculateFoo(var1, withBar: var2)
    

    The internal names foo and bar are only accessible inside the function/method. The external names provide the argument labels which you use to call the function.

    In your case, you need to use the internal name nibBundle. That's the one accessible inside the function body.

提交回复
热议问题