Instance Method

fileAttributesToWriteToURL:forSaveOperation:error:

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

Declaration

- (NSDictionary *)fileAttributesToWriteToURL:(NSURL *)url forSaveOperation:(UIDocumentSaveOperation)saveOperation error:(NSError * _Nullable *)outError;

Parameters

url

A file URL locating the document 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 UIDocumentSaveOperation for details.

outError

If you override this method and cannot write the document data for any reason, return by indirection an NSError object that encapsulates the reasons why you can’t. Otherwise, ignore this parameter.

Return Value

A dictionary of file attributes—for example, level of file protection and creation date. See NSFileManager for more information about file attributes.

Discussion

The attributes are associated with a specific file type and save operation. You can override this method to return a dictionary of file attributes that are different than the default file attribute, which for new files is NSFileExtensionHidden.

The saveToURL:forSaveOperation:completionHandler: calls this method before executing asynchronous writing. It passes the dictionary into writeContents:andAttributes:safelyToURL:forSaveOperation:error: when it calls that method to write the document file.

See Also

Writing Document Data

closeWithCompletionHandler:

Asynchronously closes the document after saving any changes.

contentsForType:error:

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

saveToURL:forSaveOperation:completionHandler:

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

writeContents:andAttributes:safelyToURL:forSaveOperation:error:

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

writeContents:toURL:forSaveOperation:originalContentsURL:error:

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

savingFileType

Returns the file type to use for saving a document.

fileNameExtensionForType:saveOperation:

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