<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileWrapper/preferredFilename",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileWrapper(py)preferredFilename"
  },
  "title" : "preferredFilename"
}
-->

# preferredFilename

The preferred filename for the file wrapper object.

```
var preferredFilename: String? { get set }
```

## Discussion

This name is normally used as the dictionary key when a child file wrapper is added to a directory file wrapper. However, if another file wrapper with the same preferred name already exists in the directory file wrapper when this object is added, the filename assigned as the dictionary key may differ from the preferred filename.

When you change the preferred filename, the default implementation of this property causes the existing parent directory file wrappers to remove and re-add the child to accommodate the change. Preferred filenames of children are not preserved when you write a file wrapper to disk and then later instantiate another file wrapper by reading the file from disk. If you need to preserve the user-visible names of attachments, you have to store the names yourself.

## See Also

[`-  addFileWrapper:`](/documentation/Foundation/FileWrapper/addFileWrapper(_:))

Adds a child file wrapper to the receiver, which must be a directory file wrapper.

[`-  initWithURL:options:error:`](/documentation/Foundation/FileWrapper/init(url:options:)-70161)

Initializes a file wrapper instance whose kind is determined by the type of file-system node located by the URL.

[`-  writeToURL:options:originalContentsURL:error:`](/documentation/Foundation/FileWrapper/write(to:options:originalContentsURL:))

Recursively writes the entire contents of a file wrapper to a given file-system URL.

[`-  initDirectoryWithFileWrappers:`](/documentation/Foundation/FileWrapper/init(directoryWithFileWrappers:))

Initializes the receiver as a directory file wrapper, with a given file-wrapper list.



---

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)