A specialized view controller for previewing an item.


class QLPreviewController : UIViewController


A QLPreviewController can display previews for many common file types, including the following:

  • iWork documents

  • Microsoft Office documents

  • Rich Text Format, or RTF, documents

  • PDF files

  • Images

  • Text files with a uniform type identifier (UTI) that conforms to the public.text type. To learn more about UTIs, see the Uniform Type Identifiers Reference.

  • Comma-separated value, or CSV, files

  • 3D models in the usdz format with both standalone and AR views for viewing the model

On iOS devices, you can present a QLPreviewController modally by calling present(_:animated:completion:) from a presenting UIViewController, or you can push it into view using a UINavigationController. The preview includes a title taken from the last path component of the item URL. You can override it by implementing a previewItemTitle accessor for the preview item.

To use a preview controller, you must provide a data source object. The data source provides preview items to the controller and tells it how many items to include in a preview navigation list. If there’s more than one item in the list, a modally presented controller displays navigation arrows to let the user switch among the items. If you pushed a preview controller into view using a navigation controller, you can provide buttons in the navigation bar for moving through the navigation list.

For details on providing items to a preview controller, see QLPreviewControllerDataSource and QLPreviewItem.


Configuring a Preview Controller

var dataSource: QLPreviewControllerDataSource?

The preview controller’s data source.

protocol QLPreviewControllerDataSource

The data source for a preview controller must adopt this protocol to provide preview items to the controller.

var delegate: QLPreviewControllerDelegate?

The preview controller’s delegate object.

protocol QLPreviewControllerDelegate

The delegate of a preview controller must adopt this protocol.

Managing Item Previews

class func canPreview(QLPreviewItem) -> Bool

Indicates whether or not the Quick Look preview controller can display an item.

var currentPreviewItem: QLPreviewItem?

The item currently displayed in the Quick Look preview controller.

var currentPreviewItemIndex: Int

The index, within the preview item navigation list, of the item currently displayed in the Quick Look preview controller.

func refreshCurrentPreviewItem()

Asks the Quick Look preview controller to recompute the display of the current preview item.

func reloadData()

Asks the preview controller to reload its data from its data source.

See Also

Previews and Thumbails

protocol QLPreviewItem

A protocol that defines properties you implement to make your application’s content visible in a preview.

protocol QLPreviewingController

A protocol for implementing a custom controller to create previews of files.

Previews or Thumbnail Images for macOS 10.14 or Earlier

Create thumbnail images or previews of common files and custom file types on earlier versions of macOS.