---
title: "fileNameExtension(forType:saveOperation:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uidocument/filenameextension(fortype:saveoperation:)"
---

# fileNameExtension(forType:saveOperation:)

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

## Declaration

```swift
func fileNameExtension(forType typeName: String?, saveOperation: UIDocument.SaveOperation) -> String
```

## Parameters

- `typeName`: A Uniform Type Identifier (UTI) that indicates the type of document (for example, PDF or HTML).
- `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 string to use as the file extension of the document file.

## Discussion

Discussion The default implementation queries Launch Services to obtain the file extension matching the file (document) type. You can override this method to return a file extension that’s different from the default extension. The default implementation of the save(to:for:completionHandler:) method calls this method before it gets the document content and writes the document file to disk.

## 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)
- [fileAttributesToWrite(to:for:)](uikit/uidocument/fileattributestowrite(to:for:).md)
