Saving to a File

Before we can save the contents of a MathPaper window into a file, we first need to know what kind of file our application will create. Specifically, we need to know the file’s HFS creator code, its HFS type code, and its file extension.

Creator codes are used so that when you double-click on a filename in the Finder, Cocoa knows to open the correct application. Creator codes are also used to locate applications on the computer’s hard disk. You may remember that, in Section 10.4.5, we were assigned by Apple a creator code for the MathPaper application. That creator code was MATP.

Because a single application can create many different kinds of files, and because multiple applications are sometimes able to read the same file, document files stored on HFS filesystems also have a type code . Like creator codes, file type codes are 4-byte strings or 32-bit quantities. In many cases, the file type is the same as the file’s extension in the world of Windows and Unix: GIF and JPEG are used for image files, for example.

In addition to creator codes, Mac OS X uses file extensions to match up applications and their document files. A file extension is the set of letters that come after the last period (dot) in a file’s name. Unlike the Mac OS 9 Finder, the Mac OS X Finder makes it somewhat difficult for the user to accidentally change a file extension. It does this by generally hiding file extensions and by warning the user before an extension is changed. Mac OS relies ...

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.