Continuing the deluge of interesting Swift proposals, we have one for an Observation system that could integrate with SwiftUI, from @phausler: https://forums.swift.org/t/pitch-observation/62051
A fun historical note: long ago (2013? 2012?) Andy Matuschak, Colin Barrett, and I were prototyping a very early pre-Swift version of what later turned into Combine. Andy came up with a gloriously terrible hack where you'd write a block something along the lines of this:
[NSObservableBlock(^{
return @([thingOne propertyOne] + [thingTwo propertyTwo]);
}) observeWithKeyPath: @"foo.bar"];
and the observation runtime would do the following:
- Inspect the block memory layout to find all the captured objects
- Swizzle every property getter on every captured object
- Run the block to get an initial value, and record which overridden property getters were called
- Install KVO observers on all the recorded properties
- Automatically re-run the block any time any of them change
- Set
foo.barto the return value of the block
Completely, unshippably, horrendously awful, but it was so nice to use.
Philippe's new ObservationTracking machinery reads like a shippable spiritual successor to that hack.