Skip to content

Instantly share code, notes, and snippets.

@boylee1111
Created April 3, 2015 10:25
Show Gist options
  • Save boylee1111/ff2ad3dcb0a69b92adb4 to your computer and use it in GitHub Desktop.
Save boylee1111/ff2ad3dcb0a69b92adb4 to your computer and use it in GitHub Desktop.
A Swift Tour. Write an enumeration that conforms to this protocol.
protocol ExampleProtocol {
var simpleDescription: String { get }
mutating func adjust()
}
enum SimpleEnum : String, ExampleProtocol {
case Before = "", After = " (whatever)"
var simpleDescription: String {
get {
return "A simple enum." + self.rawValue
}
}
mutating func adjust() {
self = .After
}
}
var c = SimpleEnum.Before
c.adjust()
c.simpleDescription
@iDevSpread
Copy link

Hi, I typed your code but Xcode(8.3.2) gave me a compiler error for raw type error. The codes in the following are modified according to your codes.

enum SimpleEnumeration: ExampleProtocol {
	case Before, After
	var simpleDescription: String {
		get {
		    return "A simple enum."
		}
	}
	
	mutating func adjust() {
		self = .After
	}

}

var c = SimpleEnumeration.Before
a.adjust()
c.simpleDescription

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment