Contents

writeContents(_:to:for:originalContentsURL:)

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

Declaration

func writeContents(_ contents: Any, to url: URL, for saveOperation: UIDocument.SaveOperation, originalContentsURL: URL?) throws

Parameters

  • contents:

    The document data to write to disk. Typically, the data is encapsulated by an Nsdata object (if a flat file) or an Filewrapper object (if a file package).

    If the object encapsulating the document data is of some other type, you should override this method or Writecontents(_:andattributes:safelyto:for:) to perform the actual writing of the data.

  • url:

    A file URL specifying the location of the document file in the application sandbox.

  • saveOperation:

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

  • originalContentsURL:

    A file URL specifying the previous location of the document file (if not nil).

Discussion

This method is called by the writeContents(_:andAttributes:safelyTo:for:) to write the actual file data. It is passed the contents object returned from your contents(forType:) implementation. The default implementation of this method supports NSData or FileWrapper contents by asking the contents object to save itself to the corresponding URL.

If you override this method, you may choose to return a different type of data from contents(forType:) or you may choose to not override contents(forType:) and generate the writable data directly within this method. If you override this method, you should not invoke the superclass implementation.

See Also

Writing document data