Contents

data(ofType:)

Creates and returns a data object that contains the contents of the document, formatted to a specified type.

Declaration

func data(ofType typeName: String) throws -> Data

Parameters

  • typeName:

    The string that identifies the document type.

Return Value

A data object containing the document contents, or, if the data object could not be created, nil.

Discussion

The default implementation of this method throws an exception because at least one of the writing methods (this method, write(to:ofType:), fileWrapper(ofType:), or write(to:ofType:for:originalContentsURL:)) must be overridden.

For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method instead invokes dataRepresentationOfType:``typeName on self if dataRepresentationOfType: is overridden.

See Also

Writing the Document’s Content