NSTextStorage
The fundamental storage mechanism of TextKit that contains the text managed by the system.
Declaration
class NSTextStorageOverview
NSTextStorage is a semi-concrete subclass of NSMutableAttributedString that adds behavior for managing a set of client NSLayoutManager objects. A text storage object notifies its layout managers of changes to its characters or attributes, which lets the layout managers redisplay the text as needed.
You can access a text storage object from any thread of your app, but your app must guarantee access from only one thread at a time.
In macOS, this class also defines properties for getting and setting scriptable attributes of NSTextStorage objects. Unless you’re dealing with scriptability, you shouldn’t access these properties directly. In particular, using the characters, words, or paragraphs properties is an inefficient way to manipulate the text storage, since accessing these properties involves the creation of many objects. Instead, use the text access methods defined by NSMutableAttributedString, NSAttributedString, NSMutableString, and NSString to perform character-level manipulation.
Subclassing Notes
The NSTextStorage class implements change management through the beginEditing() and endEditing() methods, as well as verification of attributes, delegate handling, and layout management notification. The one aspect it doesn’t implement is managing the actual attributed string storage, which subclasses manage by overriding the two NSAttributedString primitives:
Subclasses must also override two NSMutableAttributedString primitives:
These primitives should perform the change, then call edited(_:range:changeInLength:) to let the parent class know there are changes.