Swiftpack.co - happn-app/KVObserver as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by happn-app.
happn-app/KVObserver 0.9.5
A Safer KVO
⭐️ 4
🕓 3 years ago
.package(url: "https://github.com/happn-app/KVObserver.git", from: "0.9.5")


Platforms SPM compatible License happn

A safer KVO.



let kvObserver = KVObserver()
let observedObject = ObservedObject()

/* Start observing observedObject */ 
let observingId = kvObserver.observe(object: observedObject, keyPath: #keyPath(ObservedObject.observableProperty), kvoOptions: [.initial], dispatchType: .asyncOnMainQueueDirectInitial, handler: { [weak self] change in
   /* Handle changes here */

/* End observing observedObject */ 
kvObserver.stopObserving(id: observingId)
/* Or, stop observing everything */

There are many dispatch types available, all of them with their subtle differences. Usually you’ll need the default one: .asyncOnMainQueueDirectInitial. This will dispatch the inital KVO firing synchronously (if there is one, that is if the .inital KVO option has been set), and further KVO firing asynchronously on the main thread.

Don’t hesitate to read the code to learn about the other dispatch types! All of the types are documented. There even are dispatch types specifically for CoreData.


  • ☑ Re-registration skipping
  • ☐ Support for Swift 4 KeyPath


This project was originally created by François Lamboley while working at happn.


Stars: 4
Last commit: 3 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

KVObserver 0.9.5
3 years ago

Remove warning when using in Xcode 12

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics