Hi all, I'd appreciate some help with this problem. I have a MacOS app in which a hierarch of views all depend on the same @Observable. The views only change when the @Observable changes. I'd like to record the app's operation by capturing an image of the top-level view each time it changes, in response to the @Observable changing.

I've considered using ReplayKit to record video, but it doesn't seem ideal because:

  1. It won't capture one frame for each change to the view.
  2. If anything interrupts the program's operation, the video will be lost.
    So instead, I'm thinking of capturing images from the view, as described here: Recording a UIView

My problem is: How can I set it up to a call a function each time the view changes? I've seen suggestions of using .onAppear, but that seems to only get called when the view is first created. I've considered using .onChange, which can be tied to changes to my @Observable variable, but I suspect the function will get called immediately when the variable changes, rather than after the view has been updated.

Could anyone please suggest a way to ensure a function gets called after the view fully updates? Thank you.