Instantly share code, notes, and snippets.

@fitomad fitomad/kvo_observer.swift Secret
Last active Feb 2, 2019

Embed
What would you like to do?
import Foundation
public class Observador: NSObject
{
/// Nada interesante que inicializar
override public init()
{
print("Soy el observador")
}
/**
Aquí se nos notifican los cambios
*/
override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
{
guard let keyPath = keyPath, let change = change else
{
return
}
if let newName = change[NSKeyValueChangeKey.newKey], let oldName = change[NSKeyValueChangeKey.oldKey]
{
print("La propiedad con el keyPath '\(keyPath)' antes era \(oldName) y ahora tiene el valor \(newName)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment