The Learn the Essentials of Swift playground has an example protocol:
protocol ExampleProtocol {
var simpleDescription: String { get }
func adjust()
}
After this example, there is a short excerpt that states:
Note : {get}, following the simpleDescription property, indicates that it is read-only, which means that the value of the property can be viewed, but never changed.
Additionally, an example of a class corresponding to this protocol is provided:
class SimpleClass: ExampleProtocol {
var simpleDescription: String = "A very simple class."
var anotherProperty: Int = 69105
func adjust() {
simpleDescription += " Now 100% adjusted."
}
}
var a = SimpleClass()
a.adjust()
let aDescription = a.simpleDescription
However, how does this class fit the protocol? What prevents me from mutating simpleDescription? What? I do not understand?

source
share