Xcode遇到了一个奇怪的错误:
无法使用(Double,@ value Double)参数列表调用'+ ='
使用iOS SDK 8.1和Xcode 6.1.1给出以下代码。 (您可以简单地将其放入Playground并进行测试。)
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说total
是Double
,mark
是Mark
,我认为mark.mark
必须是定义的Double
。< / p>
我是否缺少导入模块?我此刻只导入Foundation
,我认为应该足够了。