enum Suit {
case Spades, Hearts, Diamonds, Clubs
func simpleDescription() -> String {
switch self {
case .Spades:
return "spade"
case .Hearts:
return "hearts"
case .Diamonds:
return "diamonds"
case .Clubs:
return "clubs"
}
}
func color() -> String {
switch self {
case .Clubs:
return "black"
case .Spades:
return "black"
case .Hearts:
return "red"
case .Diamonds:
return "red"
}
}
}
let hearts = Suit.Hearts
let heartsDescription = hearts.simpleDescription()
let spade = Suit.Spades
let spadeColor = spade.color()
println(heartsDescription)
println(spadeColor)
let diamond = Suit.Diamonds
let diamondColor = diamond.color()
println(diamondColor)
--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swift-languag...@googlegroups.com.
To post to this group, send email to swift-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/cf3a2aa2-2a04-4cd3-8c3b-a696f416e508%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
func color() -> String {
switch self {
case .Clubs:
case .Spades:
return "black"
case .Hearts:
case .Diamonds:
return "red"
}
}
It looks right to me, other than that personally I'd use computed properties instead of methods for both color() and simpleDescription(). Which part is making you question it?Sam