Enum
enum ColorSpace {
case RGB(Int, Int, Int)
case CMYK(Float, Float, Float, Float)
func description() -> String {
switch self {
case .RGB(let r, let g, let b):
return "R: \(r), G: \(g), B: \(b)"
case .CMYK(let c, let m, let y, let k):
return "C: \(c), M: \(m), Y: \(y), K: \(k)"
}
}
}
let red = ColorSpace.RGB(255, 0, 0)
println(red.description())
// R: 255, G: 0, B: 0
let orange = ColorSpace.CMYK(0.0, 25.88, 70.98, 0.0)
println(orange.description())
// C: 0.0, M: 25.87999, Y: 70.98000, K: 0.0