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
// sintaxis de un protocolo | |
protocol UnProtocolo { | |
// aquí va la definición | |
} |
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
class CuentaDeAhorros { | |
var saldo: Double = 0 | |
} |
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
let cuenta = CuentaDeAhorros() | |
cuenta.saldo = 5 |
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
protocol CuentaDeAhorrosDelegate { | |
func notificarCambioDeSaldo(saldoActual: Double, nuevoSaldo: Double) | |
} |
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
class Notificador : CuentaDeAhorrosDelegate { | |
func notificarCambioDeSaldo(saldoActual: Double, nuevoSaldo: Double) { | |
print("El saldo actual es $(saldoActual) y el nuevo saldo será $(nuevoSaldo)") | |
} | |
} |
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
class CuentaDeAhorros { | |
var delegate: CuentaDeAhorrosDelegate? | |
var saldo: Double = 0 { | |
willSet(nuevoSaldo) { | |
delegate?.notificarCambioDeSaldo(saldo, nuevoSaldo: nuevoSaldo) | |
} | |
} | |
} |
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
let notificador = Notificador() | |
let cuenta = CuentaDeAhorros() | |
cuenta.delegate = notificador | |
cuenta.saldo = 5 | |
cuenta.saldo = 20 |
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
enum UnaEnumeracion { | |
// aquí va la definición | |
} |
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
enum PosicionesCampoBeisbol { | |
case Lanzador | |
case Receptor | |
case PrimeraBase | |
case SegundaBase | |
case TerceraBase | |
case Campocorto | |
case JardineroIzquierdo | |
case JardineroCentral | |
case JardineroDerecho |
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
enum DiasSemana { | |
case Lunes, Martes, Miercoles, Jueves, Viernes, Sabado, Domingo | |
} |
OlderNewer