---
title: "fileAttributesToWrite(to:for:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uidocument/fileattributestowrite(to:for:)"
---

# fileAttributesToWrite(to:for:)

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

## Declaration

```swift
func fileAttributesToWrite(to url: URL, for saveOperation: UIDocument.SaveOperation) throws -> [AnyHashable : Any]
```

## 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’s being overwritten. See doc://com.apple.uikit/documentation/UIKit/UIDocument/SaveOperation for details.

## Return Value

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

## Discussion

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 extensionHidden. The save(to:for:completionHandler:) calls this method before executing asynchronous writing. It passes the dictionary into writeContents(_:andAttributes:safelyTo:for:) when it calls that method to write the document file. note: 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.

## See Also

### Writing document data

- [close(completionHandler:)](uikit/uidocument/close(completionhandler:).md)
- [contents(forType:)](uikit/uidocument/contents(fortype:).md)
- [save(to:for:completionHandler:)](uikit/uidocument/save(to:for:completionhandler:).md)
- [writeContents(_:andAttributes:safelyTo:for:)](uikit/uidocument/writecontents(_:andattributes:safelyto:for:).md)
- [writeContents(_:to:for:originalContentsURL:)](uikit/uidocument/writecontents(_:to:for:originalcontentsurl:).md)
- [savingFileType](uikit/uidocument/savingfiletype.md)
- [fileNameExtension(forType:saveOperation:)](uikit/uidocument/filenameextension(fortype:saveoperation:).md)
