Swift error cannot call '+' with argument list like '($ T28, $ T32)'

I'm getting a weird error that I can't help but think, but this is a compiler error. In Swift, playground or iOS app, if I do the following ...

let array = [0, 1, 2, 3, 4, 5]
let sum = array[0] + array[1] + array[2] + array[3] + array[4] + array[5]


... I am getting the following compiler error.

cannot invoke '+' with an argument list of type '($T28, $T32)'


Just for fun, I changed this to an array of strings and I get the same thing. However, if I just add the first five values, there are no errors. Leaving aside the fact that this is not the best way to summarize these numbers, how is it not a compiler error?

And if it's not a compiler error, why isn't it?


source to share

1 answer

if you try to create an array of integers:

let array:[Int] = [0, 1, 2, 3, 4, 5] 


I had the same problem. I think the compiler did not recognize the type of your array values.

If you are using:

let sum = Int(array[0]) + Int(array[1]) + Int(array[2]) + Int(array[3]) + Int(array[4]) + Int(array[5])


works as expected.



All Articles