I am having an issue with refreshing a text edit field in an AppKit (NS) window. I'm coming from long experience with UIKit to AppKit, so I'm still banging into some guardrails.
I have a base settings class, like so (all this is pcode. I can point to the actual code, but it's a bit wordy for an SO question):
class A: NSObject {
var liveDataObject: Int = 0
func reset() { liveDataObject = 0 }
}
class B: A {
@objc dynamic var liveDataObjectAccessor: Int {
get { return liveDataObject }
set { liveDataObject = newValue }
}
}
Now, if I use the IB Bindings to associate an instance of B
, and its liveDataObjectAccessor
calculated property with an NSTextField
, it works great. Changes to the text field are reflected in the data.
If I then have a "RESET" button that calls the A.reset()
method, I would expect the text field to reflect 0 (if it had been changed by the user, say they entered "1").
However, what I am experiencing, is that the A.liveDataObject
is set to 0, but the text field continues to display "1".
How do I make sure the text field gets updated when the underlying value is changed?