swift向方法传数组参数的语法

Posted chenyangsocool

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift向方法传数组参数的语法相关的知识,希望对你有一定的参考价值。

总是记不住向方法中传数组参数的语法,所以记录一下。

func calculateStatistics(scores:[Int]) -> (min:Int,max:Int,sum:Int) {
    var min = scores[0]
    var max = scores[0]
    var sum = 0
    
    for score in scores {
        if score>max {
            max=score
        }
        else if score<min{
            min=score
        }
        sum += score
    }
    return (min,max,sum)
}
let a=calculateStatistics([5,3,100,3,9])
print(a.min)
print(a.sum)
print(a.0)
最主要的是这句:func calculateStatistics(scores:[Int]) -> (min:Int,max:Int,sum:Int) {}

以上是关于swift向方法传数组参数的语法的主要内容,如果未能解决你的问题,请参考以下文章