The Cocoa text system’s architecture is both modular and layered to enhance its ease of use and flexibility. Its modular design reflects the model-view-controller paradigm (originating with Smalltalk-80) where the data, its visual representation, and the logic that links the two are represented by separate objects. In the case of the text system, NSTextStorage holds the model’s text data, NSTextContainer models the geometry of the layout area, NSTextView presents the view, and NSLayoutManager intercedes as the controller to make sure that the data and its representation onscreen stay in agreement.
This factoring of responsibilities makes each component less dependent on the implementation of the others and makes it easier to replace individual components with improved versions without having to redesign the entire system. To illustrate the independence of the text-handling components, consider some of the operations that are possible using different subsets of the text system:
Using only an NSTextStorage object, you can search text for specific characters, strings, paragraph styles, and so on.
Using only an NSTextStorage object you can programmatically operate on the text without incurring the overhead of laying it out for display.
Using all the components of the text system except for an NSTextView object, you can calculate layout information, determining where line breaks occur, the total number of pages, and so forth.
The layering of the text system reduces the amount you have to learn to accomplish common text-handling tasks. In fact, many applications interact with this system solely through the API of the NSTextView class.
© 1997, 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-04-08)