<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIDocument/fileNameExtension(forType:saveOperation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)fileNameExtensionForType:saveOperation:"
  },
  "title" : "fileNameExtension(forType:saveOperation:)"
}
-->

# fileNameExtension(forType:saveOperation:)

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

```
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 [`UIDocument.SaveOperation`](/documentation/UIKit/UIDocument/SaveOperation) for details.

## Return Value

A string to use as the file extension of the document file.

## 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:)`](/documentation/UIKit/UIDocument/save(to:for:completionHandler:)) method calls this method before it gets the document content and writes the document file to disk.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)