< Previous PageNext Page > Hide TOC

Uniform Type Identifier Concepts

Uniform type identifiers (UTIs) provide a unified way to identify data handled within the system, such as documents, pasteboard data, and bundles. This chapter describes the concepts behind UTIs and shows how to specify them in your application bundles.

In this section:

What Is a Uniform Type Identifier?
Identifier Tags
Declaring UTIs


What Is a Uniform Type Identifier?

A uniform type identifier is a string that uniquely identifies a class of entities considered to have a “type.” For example, for a file or other stream of bytes, “type” refers to the format of the data. For entities such as packages and bundles, “type” refers to the internal structure of the directory hierarchy. Most commonly, a UTI provides a consistent identifier for data that all applications and services can recognize and rely upon, eliminating the need to keep track of all the existing methods of tagging data. Currently, for example, a JPEG file might be identified by any of the following methods:

A UTI replaces all these incompatible tagging methods with the string public.jpeg. This string identifier is fully compatible with any of the older tagging methods, and you can call utility functions to translate from one to the other. That is, for a given UTI, you can generate the equivalent OSType, MIME type, or filename extension, and vice versa.

Because UTIs can identify any class of entity, they are much more flexible than the older tagging methods; you can also use them to identify any of the following entities:

In addition, you can define your own UTIs for application-specific use. For example, if your application uses a special document format, you can declare a UTI for it. Third-party applications or plug-ins that want to support your format can then use that UTI to identify your files.

The UTI Character Set

A uniform type identifier is a Unicode string that usually contains characters in the ASCII character set. However, only a subset of the ASCII characters are permitted. You may use the Roman alphabet in upper and lower case (A–Z, a–z), the digits 0 through 9, the dot (“.”), and the hyphen (“-”). This restriction is based on DNS name restrictions, set forth in RFC 1035.

Uniform type identifiers may also contain any of the Unicode characters greater than U+007F.

Important: Any illegal character appearing in a UTI string—for example, underscore ("_"), colon (":"), or space (" ")—will cause the string to be rejected as an invalid UTI. At the API layer, no error is generated for invalid UTIs.

The UTI Syntax

Uniform type identifiers use the reverse-DNS format initially used to describe elements of the Java class hierarchy and now also used in Mac OS X for bundle identification. Some examples:

com.apple.quicktime-movie
com.mycompany.myapp.myspecialfiletype
public.html
com.apple.pict
public.jpeg

The UTI syntax ensures that a given identifier is unique without requiring a central authority to register or otherwise keep track of them. Note that the domain (com, public, and so on) is used only to identify the UTIs position in the domain hierarchy; it does not imply any grouping of similar types.

You declare UTIs in the Info.plist file of a bundle. See “Declaring UTIs” for more information. As of Mac OS X v10.4, you can declare UTIs in any of the following:

Conformance

A key advantage of uniform type identifiers over other type identification methods is that they are declared in a conformance hierarchy. A conformance hierarchy is analogous to a class hierarchy in object-oriented programming. Instead of “type A conforms to type B,” you can also think of this as “all instances of type A are also instances of type B.”

Figure 1-1 shows a conformance hierarchy for some uniform type identifiers.


Figure 1-1  A conformance hierarchy

A conformance hierarchy

For example, the UTI public.html, which defines HTML text, conforms to the base text identifier, public.text. In this case, conformance lets applications that can open general text files identify HTML files as ones it can open as well.

You need to declare conformance only with your type’s immediate “superclass,” because the conformance hierarchy allows for inheritance between identifiers. That is, if you declare your identifier as conforming to the public.tiff identifier, it automatically conforms to identifiers higher up in the hierarchy, such as public.image and public.data.

The conformance hierarchy supports multiple inheritance. For example, the UTI for an application bundle (com.apple.application-package) conforms to both the generic bundle type (com.apple.bundle) and the packaged directory type (com.apple.package).

When specifying conformance for your UTI, your items should ideally conform to both a physical and functional hierarchy. That is, the conformance should specify both its physical nature (a directory, a file, and so on) as well as its usage (an image, a movie, and so on).

While conforming to the functional hierarchy is not mandatory, doing so allows for better integration with system features. For example, Spotlight associates named attributes (title, authors, version, comments, and so on) with functional UTIs.

Figure 1-2 shows examples of physical and functional hierarchies:


Figure 1-2  Physical and functional hierarchies

Physical and functional hierarchies

In some cases, you need to declare conformance to only one UTI to cover both hierarchies. For example, public.text, public.image and public.audiovisual-content conform to both public.data (physical) and public.content (functional), so conforming (directly or indirectly) to one of these items covers both hierarchies.

Conformance gives your application much more flexibility in determining what types it is compatible with; not only do you avoid writing lots of conditional code, your application can be compatible with types that you had never anticipated.

Dynamic Type Identifiers

Sometimes you may run across an data type that does not have a UTI declared for it. UTIs handle this case transparently by creating a dynamic identifier for that type. For example, say your application finds a NSPasteboard type that it does not recognize. Using the utility functions, it can still convert the type to a UTI that it can then pass around.

Dynamic identifiers have the domain dyn, with the rest of the string that follows being opaque. You handle dynamic identifiers just as any other UTI, and you can extract the original identifier tag using utility functions. You can think of a dynamic identifier as a UTI-compatible wrapper around an otherwise unknown filename extension, MIME type, OSType, and so on.

Identifier Tags

Each UTI can have one or more tags associated with it. These tags indicate alternate methods of type identification, such as filename extension, MIME type, or NSPasteboard type. You use these tags to assign specific extensions, MIME types, and so on, as being equivalent types in a UTI declaration.

For example, the public.jpeg identifier declaration includes one OSType tag ('JPEG') and two filename extension tags (.jpg and .jpeg). These tags are then considered alternate identifiers for the public.jpeg type.

Essentially, you use the tags to group all the possible methods of identifying a type under one UTI. That is, a file with extension .jpg or .jpeg, or an OSType of 'JPEG' are all considered to be of type public.jpeg.

Declaring UTIs

You declare uniform type identifiers in the Info.plist file of:

In addition to declaring the UTI string, the declaration can contain any of the following properties:

Your UTI declarations must be either imported or exported:

If both imported and exported declarations for a UTI exist, the exported declaration takes precedence over imported one.

Here is a sample declaration for the public.jpeg UTI, defined as an exported type, as you would find in a property list:

 <key>UTExportedTypeDeclarations</key>
        <array>
            <dict>
                <key>UTTypeIdentifier</key>
                <string>public.jpeg</string>
                <key>UTTypeReferenceURL</key>
                <string>http://www.w3.org/Graphics/JPEG/</string>
                <key>UTTypeDescription</key>
                <string>JPEG image</string>
                <key>UTTypeIconFile</key>
                <string>public.jpeg.icns</string>
                <key>UTTypeConformsTo</key>
                <array>
                    <string>public.image</string>
                    <string>public.data</string>
                </array>
                <key>UTTypeTagSpecification</key>
                <dict>
                    <key>com.apple.ostype</key>
                    <string>JPEG</string>
                    <key>public.filename-extension</key>
                    <array>
                        <string>jpeg</string>
                        <string>jpg</string>
                    </array>
                    <key>public.mime-type</key>
                    <string>image/jpeg</string>
                </dict>
            </dict>
        </array>

Table 1-1 shows a list of the available property key lists that you use in UTI declarations.

Table 1-1  Property list keys for uniform type identifiers

Key

Value type

Description

UTExportedTypeDeclarations

array of dictionaries

An array of exported UTI declarations (that is, identifiers owned by the bundle’s publisher).

UTImportedTypeDeclarations

array of dictionaries

An array of imported UTI declarations (that is, identifiers owned by another company or organization).

UTTypeIdentifier

string

The UTI for the declared type. This key is required for UTI declarations.

UTTypeTagSpecification

dictionary

A dictionary defining one or more equivalent type identifiers.

UTTypeConformsTo

array of strings

The UTIs to which this identifier conforms.

UTTypeIconFile

string

The name of the bundle icon resource to associate with this UTI.

UTTypeDescription

string

A user-visible description of this type (may be localized).

UTTypeReferenceURL

string

The URL of a reference document describing this type.



< Previous PageNext Page > Hide TOC


© 2004, 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-04-08)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.