New to swift. Not sure why the complier is giving the error for the code below.:
func addNumbers(numbers: Int ...) -> Int {
var total : Int = 0
for number in numbers {
total += number
}
return total
}
func multiplyNumbers(numbers: Int ...) -> Int {
var total : Int = numbers [0]
for (index,number) in numbers.enumerate() {
if index == 0 {
continue
}
total *= number
}
return total
}
func mathOperation(mathFunction: (Int ...) -> Int, numbers: Int ...) -> Int {
return mathFunction(numbers)
}
Error:
error: cannot convert value of type '[Int]' to expected argument type 'Int' return mathFunction(numbers)
mathFunction: (Int ...)... expects a variadic argument of singleInttypes, whereasnumbersis anIntarray; e.g., the following signature is valid (but perhaps not as you intended)func mathOperation(mathFunction: ([Int]) -> Int, numbers: Int ...) -> Int { ... }. This is possibly unexpected asnumbersinmathOperationis a variadic parameter, but this is only in effect when calling the function: variadic parameters aren't really a type, so oncenumbersenter "an instance of the function", it's an array. - dfrib