swift多重返回值函数 官网
Swift里,多重返回值函数可返回多个值,借助元组实现。元组能把多个值组合成单一复合值。 func getMinMax(numbers: [Int]) -> (min: Int, max: Int) { // 定义返回的最大最小值 var minValue = numbers[0] var maxValue = numbers[0] //遍历拿到最大最小值 for number in numbers { if number maxValue { maxValue = number } } //返回 return (min: minValue, max: maxValue)} 调用此函数: let bounds = getMinMax(numbers: [8, 1, 2, 10, 3])print(Min: (bounds.min), Max: (bounds.max)) 要保证元组元素类型和返回值类型匹配。