Notice that I'm building the key path myself. This is because firstItem is of type id, and depending on what type of view it is, it may not have a font property.
If I run this code as-is, I get a crash:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DashedHairlineView 0x7fdaa492cbc0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key font.'
If I delete the callImmediately parameter and call the handler myself on the next line, it works fine, and subsequent changes successfully trigger the callback.
I'm subclassing
NSLayoutConstraint
, and I want to know when thefirstItem
’sfont
changes. So I set it up like this:Notice that I'm building the key path myself. This is because
firstItem
is of typeid
, and depending on what type of view it is, it may not have afont
property.If I run this code as-is, I get a crash:
If I delete the
callImmediately
parameter and call the handler myself on the next line, it works fine, and subsequent changes successfully trigger the callback.