TheCocoa text system (formerly known simply by the primary class nameNSText) is the linked network ofclasses,protocols,interfaces andobjects that providetypography andtext field editing capabilities and toCocoa applications onApple'smacOS, where it is the primary text-handling system.[1] Although "extremely complex", the standard text-handling abilities of the Cocoa text system have been widely praised as without peer.[2][3]It is possible to implement a fully featuredrich text editor in only a few lines of code.[4][5]
Formerly embodied[6] in developerNeXT Inc.'sOpenStepAPI specification, and implemented in NeXT'sOPENSTEP operating system, and probably also in the earlierNeXTSTEP[citation needed] platform, Cocoa's NSText has additionally been implemented via the OpenStep API specification successfully in third-party implementations such as thefree-and-open-sourceGNUstep.[6]
The Cocoa text system uses aModel–View–Controllerdesign pattern.[7] The view layer is handled by NSTextView and NSTextField, NSLayoutManager and NSTextContainer are the controller layer, and NSTextStorage (amutable attributedstring subclass) is the model.[8]
The Cocoa text system also interacts withServices to providestandard streams functionality in a GUI environment. Users interact with two classes, NSTextField (providing single-line edit fields) or NSTextView (providing multi-line editing). Each NSTextField uses ashared instance of a NSTextView called the "field editor". This was done to reduce high memory requirements that would arise if every field implemented its own NSTextViewobject graph when only one field can actually havefocus at any time.[9]
Cocoa adopts manyEmacs keybindings familiar to programmers,[10] and the default text editing keyboard shortcuts can be overridden and new custom shortcuts can be created, by creating and editing related configuration files.[11]
You'll build a word processor capable of handling kerning, justification, sub and superscripting, full Unicode support, spell checking, multiple font and paragraph styles, drag and drop of embedded graphics and colors, rulers with adjustable tab stops, reading and writing of conforming RTFD files, all in less than 13 lines of code! You cannot do this in any other development environment on the planet.
There is very little custom code in TE and what is there is basically only the code necessary to make the AppKit behave like a text editor.
![]() | This Macintosh-related article is astub. You can help Wikipedia byexpanding it. |