How to force-update Cocoa bindings?

cocoa, cocoa-bindings, macos, objective-c

Solution

If you are using bindings, then the GUI should update as long as you:

- are updating the values on the main thread (so the bindings can be updated at GUI time)

- are using the setter to update the value

So, if you're you've got the value bound to an object's `foo.zot` property, you need to make sure to call `[foo setZot: @"new value"]` on the main thread (or set the property using `foo.zot=@"new value"`).

Problem

I'm using Cocoa bindings (as in Objective-C on the Mac) to display a relative date value using a value transformer. That is, my `NSValueTransformer` subclass converts an `NSDate` instance to `NSString` to display relative dates like "3 seconds ago", "2 minutes ago", etc. As you can see, these displayed values gets outdated as time progresses and thus will need to be refreshed somehow. I know I'll need to use a timer and then force the bindings to update so that the value transformer gets re-executed and display the correct relative date. But the question is, how do I make these bindings to refresh their values?

Original source