Document Package

Document packages give the illusion of a single document to users but provide you with flexibility in how you store the document data internally.

If your document file formats are getting too complex to manage because of several disparate types of data, you might consider adopting a package format for your documents.

# Defining Your Document Directory Structure

Apple does not prescribe any specific structure for document packages. The contents and organization of the package directory are left to you.

You are encouraged, however, to create either a flat directory structure or use the framework bundle structure, which involves placing your files in a top-level Resources subdirectory. (For more information about the bundle structure of frameworks, see Framework Bundles.)

# Registering Your Document Type

To register a document as a package, you must modify the document type information in your application’s information property list (Info.plist) file. T

he CFBundleDocumentTypes key stores information about the document types your application supports.

For each document package type, include the LSTypeIsPackage key with an appropriate value. The presence of this key tells the Finder and Launch Services to treat directories with the given file extension as a package. For more information about Info.plist keys, see Information Property List Key Reference.

Document packages should always have an extension to identify them—even though that extension may be hidden by the user. The extension allows the Finder to identify your document directory and treat it as a package. You should never associate a document package with a MIME type or 4-byte OS type.

# Let's try

Open Finder on OS X, navigate to a Pages file and right-click. You'll be given the option to 'Show Package Contents' and clicking this will allow you to navigate the contents as if it were a folder - sketchytech.blogspot

Now go to a folder, it doesn't matter which one. Change its name to add the extension .pages and instantly you'll see that it gains the Pages file icon. Pages won't be able to open this file, but it thinks it will.

Next change the extension from .pages to .numbers and again you'll see the same behaviour but with a different icon. Right-click and as in the original example you'll be given the option to 'Show Package Contents'. Do this and all works as expected.