O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Text Handling

Cocoa’s text system contains a rich set of features such as text input, layout, display, editing, copying and pasting, and font management. It also includes support for advanced typesetting features such as kerning and ligature, multilingual support with Unicode, and sophisticated layout capabilities.

This chapter discusses the primary classes of Cocoa’s text handling system and how they relate to one another. Figure 5-1 shows the hierarchy of classes related to the text system.

Hierarchy of text system class

Figure 5-1. Hierarchy of text system class

Text System Architecture

The following four classes make up the core architecture of Cocoa’s text handling system:

  • NSTextStorage is the backbone data model responsible for storing text.

  • NSTextView is responsible for presentation in the view.

  • NSLayoutManager and NSTextContainer act as controllers between the model and the view.

The relationship between these core classes is based on the same Model-View-Controller (MVC) pattern used throughout the Application Kit (and discussed in Chapter 3). Figure 5-2 shows the division of responsibilities in these four classes using the MVC pattern.

How the four core text system classes relate to one another in the MVC pattern

Figure 5-2. How the four core text system classes relate to one another in the MVC pattern

Figure 5-2 shows the relationship between the four classes, but doesn’t ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required