Anybody else trying the experiments in the GuidedTour Playground? I am. But I'm kinda stuck on one near the end where you are asked to "Write an enumeration that conforms to this protocol." "This protocol" being the ExampleProtocol shown earlier, seen here:
I tried this:
but get this error, on the line highlighted above:
So, I know I'll need something like:
but I'm not sure what I need to put in the getter and setter to allow it to start with "A simple enumeration" but allow it to be changed later, such as via the adjust() function.
Any hints to get me headed in the right direction? Thanks in advance.
Code:
protocol ExampleProtocol {
var simpleDescription: String { get }
mutating func adjust()
}
I tried this:
Code:
enum SimpleEnum: ExampleProtocol {
case Enum1, Enum2
[COLOR="Red"][B]var simpleDescription: String = "A simple enumeration"[/B][/COLOR]
mutating func adjust() {
simpleDescription += " (adjusted)"
}
}
but get this error, on the line highlighted above:
Code:
'var' declarations without getter/setter not allowed here
So, I know I'll need something like:
Code:
var simpleDescription: String {
get {
// ???
}
set {
// ???
}
}
Any hints to get me headed in the right direction? Thanks in advance.