---
title: "preferredName(for:basedOn:)"
framework: testing
role: symbol
role_heading: Instance Method
path: "testing/attachable/preferredname(for:basedon:)"
---

# preferredName(for:basedOn:)

Generate a preferred name for the given attachment.

## Declaration

```swift
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

Return Value The preferred name for attachment.

## Discussion

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.
