<!--
{
  "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/transformingAttributes(_:_:)-9prm2",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation16AttributedStringV22transformingAttributesyACxm_yAC26SingleAttributeTransformerVy_xGzXEtAA0bC3KeyRzlF"
  },
  "title" : "transformingAttributes(_:_:)"
}
-->

# transformingAttributes(_:_:)

Returns an attributed string by calling a closure that transforms one attribute of a source attributed string.

```
@preconcurrency func transformingAttributes<K>(_ k: K.Type, _ c: (inout AttributedString.SingleAttributeTransformer<K>) -> Void) -> AttributedString where K : AttributedStringKey, K.Value : Sendable
```

## Parameters

`k`

The [`AttributedStringKey`](/documentation/Foundation/AttributedStringKey) that identifies the attribute to transform.

`c`

The closure that receives an [`AttributedString.SingleAttributeTransformer`](/documentation/Foundation/AttributedString/SingleAttributeTransformer) that you use to access and alter the attribute’s range and value.

## Return Value

An attributed string with the applied transformation to the specified attribute.

---

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)