I have a CoreData object, and I want to display information from that object in a NSTextField.
The object has two relevant properties:
@property (nonatomic, retain) NSString *text;
@property (nonatomic, readonly) NSAttributedString *displayText;
I would like to display the latter in the text field, but allow the user to edit the former. (The latter string is a simple transformation of the former, with some characters removed and with some attributes applied.)
How can I achieve this?
There are two more points worth noting:
the
NSTextFieldis inside aNSOutlineView, which means that the delegate methodscontrol:textShould{Begin,End}Editing:are not called correctly: see this question. This means that I can't manually set the.attributedStringValueof the field before and after editing.As my object is a subclass of
NSManagedObject, I cannot use it alongside aNSFormatterviasetObjectValue:(as it does not implement<NSCopying>). I thus can't seem to make the approach in this question work.
I'm open to either using an NSFormatter subclass, or (preferably) finding a way to bind the text displayed normally and while editing to the properties directly.
My outline view is view-based, so if there's a better fit for the job than NSTextField I am happy to use it instead.