While following Apple's book "The Swift Programming Language"
I ran across an issue while working on the "EXPERIMENT - Write a function that calculates the average of its arguments." from the first chapter.
To determine the average of a set of numbers, I want to reuse my sum of numbers [setOf(numbers: Int...)] function and divide by the count of numbers [numbers.count]. I am receiving the Error:
Could not find an overload for '__conversions' that accepts the supplied arguments
when I try to call sumOf(numbers) from my averageOf(numbers) function.
What should I change to call my sumOf(numbers) function correctly, from my averageOf(numbers) function?
func sumOf(numbers: Int...) -> Int {
var sum = 0 //0
for number in numbers {
sum += number
}
return sum //651
}
sumOf(42, 597, 12) //651
func averageOf(numbers: Int...) -> Int {
var sum = sumOf(numbers) //Issue in this line
return sum / numbers.count
}
averageOf(42, 597, 12)
Paste the code above into a new Xcode 6 playground to recreate.
Error Screenshot (I need 10 reputation points before I can post the image.)