当我这样做时:
struct Test {
var value: Int = 0
mutating func increment(amount: Int) { value += amount }
mutating func decrement(amount: Int) { value -= amount }
func apply(technique: (Int) -> ()) {
print("Before:\(value)")
technique(2)
print("After:\(value)")
}
mutating func main() {
apply(technique: increment) //Error: "Partial application of 'mutating' method is not allowed"
}
}
I get this error message: I've read this: Partial application of 'mutating' method is not allowed and can see the problem but can't work out what the alternative code should be?
我的主要要求是我想设置一系列“技术”,例如递增和递减,然后通过一个简单的调用“应用”它们。
任何帮助表示赞赏:-)