Instance Method

additionalContent(for:)

Handles writing non-Core Data content to the additional content directory in the document’s file package.

Declaration

func additionalContent(for absoluteURL: URL) throws -> Any

Parameters

absoluteURL

The URL for the additional content directory in the document’s file package.

error

Upon return, if a problem occurs, contains an error object that describes the problem.

Return Value

An object that contains the additional content for the document at absoluteURL, or nil if there is a problem.

Discussion

You override this method to perform to manage non-Core Data content to be stored in the additional content directory in the document’s file package.

If you implement this method, it is invoked automatically by contents(forType:). The returned object is passed to writeAdditionalContent(_:to:originalContentsURL:).

There is no need to invoke super’s implementation.

Special Considerations

A return value of nil indicates an error condition. To avoid generating an exception, you must return a value from this method. If it is not always the case that there will be additional content, you should return a sentinel value (for example, an NSNull instance) that you check for in writeAdditionalContent(_:to:originalContentsURL:).

The object returned from this method is passed to writeAdditionalContent(_:to:originalContentsURL:). Because writeAdditionalContent(_:to:originalContentsURL:) is executed on a different thread, you must ensure that the object you return is thread-safe. For example, you might return an NSData object containing an archive of the state you want to capture.

Additional content is not supported on iCloud.

See Also

Customizing Read and Write Operations

func readAdditionalContent(from: URL)

Handles reading non-Core Data content in the additional content directory in the document’s file package.

func writeAdditionalContent(Any, to: URL, originalContentsURL: URL?)

Handles writing non-Core Data content to the document’s file package.