What is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Jeff Younker via Cocoa-dev
Situation: - I am working in Swift 5. - I have an instance of an NSTextView. (Call it "V") - The value has already been set once. (Call this value "T1") - V is showing T1. - I have an NSAttributedString from another source. (Call this value "T2") Desired goal: - I want to se

RE: What is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Jonathan Prescott via Cocoa-dev
Did you tell V that it needs to re-load it’s display? There is a method on NSView (from which NSTextView is derived) called “needsDisplay(sic)” which sets a flag on the view so that the view will re-draw its content the next display cycle. So, after you set the content to T2, you need to call

Re: What is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Greg Weston via Cocoa-dev
> - I want to set the displayed contents of V to T2. > > What is/are the recommended way/s to do this? > > *I would hope that I could assign V.attributedString = T2, but alas the > world does not seem to be this simple.* The documentation suggests you should be working with the view’s textStorag

Re: What is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Jonathan Prescott via Cocoa-dev
Looking at the documentation for NSTextView, it is highly recommended that you manipulate the NSTextStorage associated with the view. NSTextStorage is a sub-class of NSMutableAttributedtString, so you have all of those capabilities as well. I’m just getting into this as well for my console app