jckarter

everyone already knows i'm a dog

the swift programming language is my fault to some degree. mostly here to see dogs, shitpost, fix old computers, and/or talk about math and weird computer programming things. for effortposts check the #longpost pinned tag. asks are open.


email
mailto:joe@duriansoftware.com
discord
jckarter

Catfish-Man
@Catfish-Man

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.bar to 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.


You must log in to comment.

in reply to @Catfish-Man's post: