Defaults
Defaults copied to clipboard
Combine publisher methods should use `NSObject.KeyValueObservingPublisher`
https://developer.apple.com/documentation/objectivec/nsobject/keyvalueobservingpublisher
This should reduce some overhead. Right now, they're based on the callback API.
Eventually (when this package can target macOS 10.15), I imagine the callback APIs like Defaults.observe()
could be based on the Combine publishers underneath too.
// @fredyshox In case you're interested in working on this.
I was actually thinking about using this, but I wanted the API to be similar to standard observe:
(same propagated KeyChange
value). As far as I know, KeyValueObservingPublisher does not give [NSKeyValueChangeKey: Any]
dictionary, just the new value.
It does support the old
option though. So there must be a way to get the old value.
By the way, the source for that publisher is now open source: https://github.com/apple/swift/commit/e7cd5ab17f5ce92315f0e23b269628ac2b9369ea#diff-bb784950aec7be6842901ecdef2bfbd5R44
A possible solution here: https://stackoverflow.com/questions/60386000/how-to-use-combine-framework-nsobject-keyvalueobservingpublisher
Closing as the Combine publishers will eventually be replaced by async stream ones.