Skip to content

Instantly share code, notes, and snippets.

@drumnkyle
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drumnkyle/c5fbd7331a22ca98706f to your computer and use it in GitHub Desktop.
Save drumnkyle/c5fbd7331a22ca98706f to your computer and use it in GitHub Desktop.
Problem with Swift GuidedTour enum with protocol challenge
protocol ExampleProtocol {
var simpleDescription: String { get }
mutating func adjust()
}
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
struct SimpleStructure: ExampleProtocol {
var simpleDescription: String = "A simple structure"
mutating func adjust() {
simpleDescription += " (adjusted)"
}
}
var b = SimpleStructure()
b.adjust()
let bDescription = b.simpleDescription
// Can't get this to work.
enum SimpleEnum: ExampleProtocol {
case A, B
var simpleDescription: String = "A very simple enum."
mutating func adjust() {
simpleDescription += " Now 110% adjusted."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment