Last active
December 6, 2017 20:13
-
-
Save lucianoschillagi/b321c6fe39c8ac3c2e9aeed29db2af16 to your computer and use it in GitHub Desktop.
Enumeraciónes que se conforman automáticamente al protocolo ´RawRepresentable´
This file contains 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
// Notas diatónicas | |
enum NotasDiatonicas: String { | |
case c = "Do" // hash value "0", raw value "Do" | |
case d = "Re" | |
case e = "Mi" | |
case f = "Fa" | |
case g = "Sol" | |
case a = "La" | |
case b = "Si" // hash value "6", raw value "Si" | |
} | |
let tonica = NotasDiatonicas.c | |
tonica.hashValue // prints "0" | |
tonica.rawValue // prints "Do" | |
let terceraMayor = NotasDiatonicas.e | |
terceraMayor.hashValue // prints "2" | |
terceraMayor.rawValue // prints "Mi" | |
let quintaJusta = NotasDiatonicas.g | |
quintaJusta.hashValue // prints "4" | |
quintaJusta.rawValue // prints "Sol" | |
// Lunas | |
enum CantidadLunas: Int { | |
case tierra = 1 // hash value "0", raw value "1" | |
case marte = 2 | |
case saturno = 62 // hash value "2", raw value "62" | |
} | |
let cantidadLunasMarte = CantidadLunas.marte | |
cantidadLunasMarte.rawValue // prints "2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment