Question
What is wrong with the following piece of code, and how can this be fixed?
let count: Int = 33
let sum: UInt = 8452
let average: Double = 256.12
var checksum = count + sum + average
Answer
In Swift, there is no implicit casting between data types. Therefore an explicit conversion is required to covert all variables to the same data type before evaluating the expression. This can be fixed as follows:
var checksum = Double(count) + Double(sum) + average