Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created August 4, 2019 15:20
Show Gist options
  • Save laevandus/97c564d697f29829d6195ffd747a77ae to your computer and use it in GitHub Desktop.
Save laevandus/97c564d697f29829d6195ffd747a77ae to your computer and use it in GitHub Desktop.
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