<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributedString/SingleAttributeTransformer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation16AttributedStringV26SingleAttributeTransformerV"
  },
  "title" : "AttributedString.SingleAttributeTransformer"
}
-->

# AttributedString.SingleAttributeTransformer

A type that transforms an attribute by altering its range or value, or by replacing it entirely.

```
@preconcurrency struct SingleAttributeTransformer<T> where T : AttributedStringKey, T.Value : Sendable
```

## Overview

For simple transformations, the closure you provide to the `transformingAttributes(…)` methods of [`AttributedString`](/documentation/Foundation/AttributedString) can use this instance to change the attribute’s value. You can also use this instance to change the range of the string that the attribute applies to. To completely replace the attribute with an attribute of a different type, use [`replace(with:value:)`](/documentation/Foundation/AttributedString/SingleAttributeTransformer/replace(with:value:)-6bn0e).

## Topics

### Accessing the Attribute’s Range

[`var range: Range<AttributedString.Index>`](/documentation/Foundation/AttributedString/SingleAttributeTransformer/range)

The range of the attribute in the attributed string.

### Accessing the Attribute’s Value

[`var value: T.Value?`](/documentation/Foundation/AttributedString/SingleAttributeTransformer/value)

The value of the attribute.

### Replacing Attributes

[`func replace<U>(with: U.Type, value: U.Value)`](/documentation/Foundation/AttributedString/SingleAttributeTransformer/replace(with:value:)-6bn0e)

Replaces an attribute with a different attribute.

[`func replace<U>(with: KeyPath<AttributeDynamicLookup, U>, value: U.Value)`](/documentation/Foundation/AttributedString/SingleAttributeTransformer/replace(with:value:)-xg8b)

Replaces an attribute with a different attribute that a key path identifies.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

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)