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
final class Event: KeyValueObservable { | |
let observationStore = ObservationStore<Event>() | |
var title: String = "Initial Title" { | |
didSet { | |
didChangeValue(for: \Event.title) | |
} | |
} | |
} | |
final class ViewController: UIViewController { | |
let event = Event() | |
@IBOutlet weak var label: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
event.addObserver(self, keyPath: \.title, options: .initial) { (observer, title) in | |
observer.label.text = title | |
} | |
} | |
@IBAction func changeTitle(_ sender: Any) { | |
event.title = "New Title" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment