元组的定义
func calculate(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
}
if score < min {
min = score
}
sum += score
}
return (min, max, sum)
}
元组的使用
let result = calculate(scores: [10, 20, 57, 33, 98, 100, 8])
print(result.sum)
print(result.max)
print(result.0)