Creates and returns a data object that contains the contents of the document, formatted to a specified type.
SDK
- macOS 10.4+
Framework
- App
Kit
Declaration
Parameters
typeName
The string that identifies the document type.
outError
On return, if the data object could not be created, a pointer to an error object that encapsulates the reason it could not be created.
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
, file
, or write
) must be overridden.
For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method instead invokes data
type
on self
if data
is overridden.
Handling Errors in Swift:
In Swift, this method is marked with the throws
keyword to indicate that it throws an error in cases of failure.
When overriding this method, use the throw
statement to throw an NSError
, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.