-
-
Save fitomad/84fd499baad42b200735e27ea1b9deb8 to your computer and use it in GitHub Desktop.
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
// Creamos un usuario... | |
let usuario = Usuario(named: "root") | |
// ...y un observador | |
let observer = Observador() | |
// El usuario registar un observador. | |
// Va a estar al tanto de los cambios en la propiedad `nombre` | |
// Se le pasa el valor que tenía antes (.old) y el nuevo (.new) | |
usuario.addObserver(observer, forKeyPath: #keyPath(Usuario.nombre), options: [ .new, .old ], context: nil) | |
// Al cambiar el nombre el obsevador será informado del cambio | |
usuario.nombre = "regular user" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment