Why does controlTextDidChange(_ obj: Notification) not work for label ?. I want a function to be called when the stringValue of the label changes [macOS]
controlTextDidChange
(and controlTextDidBeginEditing
and controlTextDidEndEditing
) are delegate methods that report user initiated changes to an editable text field. A label is not an editable, and therefor will never send these messages.
If you want a notification of a programatic label change, I would suggest using a binding. (I'm pretty sure changing the label value will fire a value changed notification. I've never used it this way, so you'll have to verify that.)
It would probably by easier (and I do this a lot) to simply bind the text value of the control to the string property of an object. You would then set the label by changing that property. Other code that needs to be notified of this change can observe that property, or wrap the update logic inside the didSet
property observer.