Creating Text Storage

As an abstract class of a class cluster, allocating and initializing an NSTextStorage object actually produces an instance of a private subclass. You can use any NSAttributedString or NSMutableAttributedString initialization method to create an NSTextStorage object.

Having created the text storage object, you add NSLayoutManager objects to the text storage using addLayoutManager:. A single text storage object can have multiple layout managers (which is why this method name begins with “add” rather than “set”).

Creating a text storage object in this way and adding a layout manager is part of the process of assembling the text system programmatically, which is described in more detail in “Creating Text System Objects” in Cocoa Text Architecture Guide. You can also create an NSTextView object and let it assemble the text system automatically, in which case the text view creates (and later deallocates) the text storage object. For more information, see Creating an NSTextView Programmatically.