Instance Method

fileNameExtension(forType:saveOperation:)

Returns a file extension to append to the file URL of the document file being written.

Declaration

func fileNameExtension(forType typeName: String?, saveOperation: UIDocumentSaveOperation) -> String

Parameters

typeName

A Uniform Type Identifier (UTI) that indicates the type of document (for example, PDF or HTML).

saveOperation

A constant that indicates whether the document file is being written the first time or whether it is being overwritten. See UIDocumentSaveOperation for details.

Return Value

A string to use as the file extension of the document file.

Discussion

The default implementation queries Launch Services to obtain the file extension matching the file (document) type. You can override this method to return a file extension that is different from the default extension. The default implementation of the save(to:for:completionHandler:) method calls this method before it gets the document content and writes the document file to disk.

See Also

Writing Document Data

func close(completionHandler: ((Bool) -> Void)? = nil)

Asynchronously closes the document after saving any changes.

func contents(forType: String)

Override this method to return the document data to be saved.

func save(to: URL, for: UIDocumentSaveOperation, completionHandler: ((Bool) -> Void)? = nil)

Saves document data to the specified location in the application sandbox.

func writeContents(Any, andAttributes: [AnyHashable : Any]? = nil, safelyTo: URL, for: UIDocumentSaveOperation)

Ensures that document data is written safely to a specified location in the application sandbox.

func writeContents(Any, to: URL, for: UIDocumentSaveOperation, originalContentsURL: URL?)

Writes the document data to disk at the sandbox location indicated by a file URL.

var savingFileType: String?

Returns the file type to use for saving a document.

func fileAttributesToWrite(to: URL, for: UIDocumentSaveOperation)

Returns a dictionary of file attributes to associate with the document file when writing or updating it.