ios - Swift - Error calling a function from another function -
this question has answer here:
while following apple's book "the swift programming language"
i ran across issue while working on "experiment - write function calculates average of arguments." first chapter.
to determine average of set of numbers, want reuse sum of numbers [setof(numbers: int...)] function , divide count of numbers [numbers.count]. receiving error:
could not find overload '__conversions' accepts supplied arguments
when try call sumof(numbers)
averageof(numbers)
function.
what should change call sumof(numbers)
function correctly, averageof(numbers)
function?
func sumof(numbers: int...) -> int { var sum = 0 //0 number in numbers { sum += number } return sum //651 } sumof(42, 597, 12) //651 func averageof(numbers: int...) -> int { var sum = sumof(numbers) //issue in line return sum / numbers.count } averageof(42, 597, 12)
paste code above new xcode 6 playground recreate.
error screenshot (i need 10 reputation points before can post image.)
you're passing different type function expects. apparently int...
not same int[]
.
you create override accepts int[]
, returns sum.
Comments
Post a Comment