我现在正在学习 Swift 语言。
在 Apple 的文档中,我看到了一个扩展示例,例如:
extension Int: ExampleProtocol {
var simpleDescription: String {
return "The number \(self)"
}
mutating func adjust() {
self += 42
}
}
7.simpleDescription
所以我只是这样称呼adjust()
:
7.adjust()
它抛出一个错误:
Immutable value of type `Int` only has mutating members named adjust.
我不确定是什么导致了错误?谁能帮我理解这个问题?