Created
March 9, 2020 07:51
-
-
Save donly/86db95d37b36bdd647841b417c86fedf to your computer and use it in GitHub Desktop.
After implementing the description property and declaring CustomStringConvertible conformance, the Enum type provides its own custom representation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Rank: Int, CustomStringConvertible { | |
case ace = 1 | |
case two, three, four, five, six, seven, eight, nine, ten | |
case jack, queen, king | |
func simpleDescription() -> String { | |
switch self { | |
case .ace: | |
return "ace" | |
case .jack: | |
return "jack" | |
case .queen: | |
return "queen" | |
case .king: | |
return "king" | |
default: | |
return String(self.rawValue) | |
} | |
} | |
var description: String { | |
return "test" | |
} | |
} | |
let ace = Rank.ace // test | |
let aceRawValue = ace.rawValue // 1 | |
let ranks: [Rank] = [.ace, .jack, .king] // [test, test, test] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment