Creating and Configuring a Quick Look Project
Xcode projects for Quick Look generators originate from a special template that sets up important aspects of the project. However, you still must specify generator-specific configuration information and add any resources for the generator, typically before you write any code.
Creating and Setting Up the Project
To create a Quick Look generator project, start by choosing New Project from the File menu in the Xcode application. In the project-creation assistant, select Quick Look Plug-In in the list of project templates (as shown in Figure 3-1) and click Next.
After you specify a name and location for the project, Xcode displays a project window similar to the example in Figure 3-2.
The following items in this window have some special relevance to Quick Look:
QuickLook.framework—The Quick Look framework, which includes both consumer and producer parts of the architecture.
If you want additional frameworks, add them to the project and insert the appropriate
#importdirectives. For example, if you want to write code using Cocoa API, add
Cocoa.frameworkto the project.
main.c— This file contains all of the code required for a
CFPlugin-based plug-in. You should not have to add or modify any of this code.
GenerateThumbnailForURL.c— The first file contains code templates for the callbacks
CancelPreviewGeneration; the second file contains code templates for the callbacks
If your implementation code is going to be Objective-C, be sure to change the extensions of these files from
min Xcode (that is, by selecting the file and choosing Rename from the File menu).
Although a Quick Look generator does not (and should not) have nib files as resources, you can add other resources if necessary.
For OS X v10.6 and later, you must build Quick Look generators for both 32- and 64-bit.
The information property list (
Info.plist) of a Quick Look generator project includes some special properties whose values you should set in addition to standard properties such as
CFBundleVersion. The following sections describe these properties.
The Content-Type UTI and CFPlugIn Properties
One important property for Quick Look generators is
LSItemContentTypes, a subproperty of
CFBundleDocumentTypes. Listing 3-1 shows the
CFBundleDocumentTypes property when unedited. (Note that the Quick Look project template specifies the value (
QLGenerator) of the
CFBundleTypeRole property for you.)
Listing 3-1 The subproperties of
<string>SUPPORTED_UTI_TYPE</string> // change this!
Replace the string “
SUPPORTED_UTI_TYPE” with one or more UTI s identifying the content types of the documents for which this generator generates thumbnails and previews. For example, the QuickLookSketch example project specifies the UTIs for Sketch documents:
For more information on Uniform Type Identifiers (UTIs) for document-content types, see Uniform Type Identifiers Overview.
As Listing 3-2 shows, a large segment of the
Info.plist in a Quick Look generator project are properties related to
CFPlugIn. You should not have to edit these properties.
Listing 3-2 CFPlugIn properties
Other Property List Keys
You can specify these additional key-value pairs in the information property list (
Info.plist) of a Quick Look generator:
Specifies the minimum use size along one dimension (in points) of thumbnails for the generator. Quick Look does not call the
This number gives Quick Look a hint for the width (in points) of previews. It uses these values if the generator takes too long to produce the preview.
This number gives Quick Look a hint for the height (in points) of previews. It uses these values if the generator takes too long to produce the preview.
Controls whether the generator can handle concurrent thumbnail and preview requests.
Controls whether the generator can be run in threads other than the main thread
QLNeedsToBeRunInMainThread are Quick Look properties that affect the multithreaded characteristics of the generator. They are discussed in Generators and Thread Safety.