You’re previewing Ry’s Cocoa Tutorial

Document Types

An application’s document types determine the file formats that it can manipulate. For example, when you double-click on a .txt file, OS X launches the TextEdit app (or a different text editor if you’ve changed your default settings). In addition, control-clicking on a .txt file and hovering over the Open With menu item lists every app capable of opening plaintext files. This is all possible due to Cocoa’s document types infrastructure.

By default, document-based apps are associated with a single document type. This is determined by the Document Extension field when configuring a new project in Xcode. In the previous chapter, we entered txt as the Document Extension, so our example app was automatically configured to manipulate .txt files.

Understanding how to alter an app’s document types is a key component of developing document-based applications. It lets you create custom file formats that only your application can open, and it also makes it possible to support multiple file formats in a single app. For instance, the TextEdit app is able to open plaintext, XML, HTML, rich text format (RTF) documents, .docx files, and more.

Opening multiple document types with a single application

In this chapter, we’ll learn how to implement similar functionality by adding multiple document types to an application. We’ll also explore how this impacts the document architecture, including the use of multiple NSDocument subclasses and custom NSDocumentController objects.

Sorry, this is the end of the preview. To read the rest of this chapter, you’ll need to purchase Ry’s Cocoa Tutorial.

Mailing List

Sign up for my low-volume mailing list to find out when new content is released. Next up is a comprehensive Swift tutorial planned for late January.

You’ll only receive emails when new tutorials are released, and your contact information will never be shared with third parties. Click here to unsubscribe.