I'm running into a weird error by Xcode:
Cannot invoke '+=' with an argument list of (Double, @lvalue Double)
Given the following code using iOS SDK 8.1 and Xcode 6.1.1. (You can simply put this into a Playground and test it.)
class Mark {
var description: String
var mark: Double
var weight: Double
init(description: String, mark: Double, weight: Double) {
self.description = description
self.mark = mark
self.weight = weight
}
}
// in some other class
var marks = [Mark(description: "", mark: 5, weight: 1), Mark(description: "", mark: 4, weight: 0.5)] // sample data
var totalMarks: Double {
let total = 0.0
for mark in marks {
total += mark.mark // Cannot invoke '+=' with an argument list of (Double, @lvalue Double)
}
return total
}
Xcode says total
is a Double
, mark
is a Mark
and I assume mark.mark
must be a Double
as defined.
Am I missing to import a module? I only import Foundation
at the moment, which I guess should be enough.