Class

UIDocumentPickerViewController

A view controller that provides access to documents or destinations outside your app’s sandbox.

Declaration

class UIDocumentPickerViewController : UIViewController

Overview

You use a document picker view controller to select a document for importing, exporting, opening, or moving.

Document Picker Modes

The document picker supports four modes. Each mode provides a slightly different approach to sharing files between apps.

  • Import an external document. The user selects an external document. The document picker copies the document, leaving the original unchanged.

  • Export a local document. The user selects an external destination. The document picker copies the document, leaving the original unchanged.

  • Open an external document. The user selects an external document. The document picker provides access to the document, and the user can edit the document in place.

  • Move a local document. The user selects an external destination. The document picker moves the document; however, the user can still access the document as an external document, and the user can edit the document in place.

Working with External Documents

Both the open and move operations grant access to documents outside your app’s sandbox. This access gives users an unprecedented amount of flexibility when working with their documents. However, it also adds a layer of complexity to your file handling. External documents have the following additional requirements:

For more about working with external documents, see Creating an Outstanding User Experience in App Extension Programming Guide.

Topics

Creating a Document Picker

init(documentTypes: [String], in: UIDocumentPickerMode)

Initializes and returns a document picker that can import or open the given file types.

init(url: URL, in: UIDocumentPickerMode)

Initializes and returns a document picker that can export or move the given document.

init(urls: [URL], in: UIDocumentPickerMode)

Initializes and returns a document picker that can export or move the given documents.

init?(coder: NSCoder)

Returns an object initialized from data in a given unarchiver.

Getting the User-Selected Document

var delegate: UIDocumentPickerDelegate?

An object that adheres to the UIDocumentPickerDelegate protocol.

var allowsMultipleSelection: Bool

A Boolean value that determines whether the user can select more than one document at a time.

protocol UIDocumentPickerDelegate

A set of methods that you implement to track when the user selects a document or destination, or to track when the operation is canceled.

Configuring a Document Picker

var documentPickerMode: UIDocumentPickerMode

The type of file transfer operation that the document picker performs.

enum UIDocumentPickerMode

Modes that define the type of file transfer operation used by the document picker.

See Also

Document Browser

Adding a Document Browser to Your App

Give users access to their local or remote documents from within your app.

Building a Document Browser-Based App

Use a document browser to provide access to the user’s text files.

class UIDocumentBrowserViewController

A view controller for browsing and performing actions on documents stored locally and in the cloud.

Building an App Based on the Document Browser View Controller

Implement a custom document file format to manage user interactions with files on different cloud storage providers.