<!--
{
  "availability" : [
    "Swift: 6.2.0 -",
    "Xcode: 26.0.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Attachable/preferredName(for:basedOn:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift Testing"
    ],
    "preciseIdentifier" : "s:7Testing10AttachableP13preferredName3for7basedOnSSAA10AttachmentVyxG_SStF"
  },
  "title" : "preferredName(for:basedOn:)"
}
-->

# preferredName(for:basedOn:)

Generate a preferred name for the given attachment.

```
borrowing func preferredName(for attachment: borrowing Attachment<Self>, basedOn suggestedName: String) -> String
```

## Parameters

`attachment`

The attachment that needs to be named.

`suggestedName`

A suggested name to use as the basis of the preferred
name. This string was provided by the developer when they initialized
`attachment`.

## Return Value

The preferred name for `attachment`.

## Discussion

The testing library uses this function to determine the best name to use
when saving `attachment`. The default implementation of this function
returns `suggestedName` without any changes.

---

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)