无法使用参数列表(Double,@ value Double)调用'+ ='

时间:2015-03-05 16:31:58

标签: ios xcode swift

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说totalDoublemarkMark,我认为mark.mark必须是定义的Double。< / p>

我是否缺少导入模块?我此刻只导入Foundation,我认为应该足够了。

0 个答案:

没有答案