NSTextView
We have our strings, we have our attributes, and we'll now take a look at the place where we put them to use: NSTextView
.
An NSTextView
, a subclass of NSText
, is actually a complex, multi-facetted object, consisting of a small, specialized stack of object types, all hidden behind what appears to the user to be nothing but a blank part of the screen. If only they knew.
NSTextView
provides the view in which the text is displayed, exposing the properties textContainer
and textStorage
, with which we can supply it with text, and display that text on the screen. The two objects that these properties expose communicate with each other via a LayoutManager
object.
The MVC pattern of text views
Cocoa's text view is in fact a microcosmic version of the Model-View-Controller design pattern followed by so much of Apple's frameworks:
NSTextStorage
is the model, containing all the string and attributes dataNSTextContainer
is the view, providing the de facto page onto which we draw textNSLayoutManager...