Why does a function call require the parameter name in Swift?

后端 未结 6 1217
夕颜
夕颜 2020-11-27 10:42

I have this Function in a class:

func multiply(factor1:Int, factor2:Int) -> Int{
    return factor1 * factor2
}

I try to call the functi

6条回答
  •  一向
    一向 (楼主)
    2020-11-27 10:57

    since you used calculator.multiply() in the example code I'm assuming this function is a method of the calculator object.

    Swift inherits a lot of things from objective-c and this is one of them:

    When in objective-c you would do (hypothetically):

    [calculator multiply:@9834 factor2:@2321];
    

    the equivalent in Swift is:

    calculator.multiply(9834, factor2:2321);
    

提交回复
热议问题