<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSLayoutManager/addTemporaryAttribute(_:value:forCharacterRange:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutManager(im)addTemporaryAttribute:value:forCharacterRange:"
  },
  "title" : "addTemporaryAttribute(_:value:forCharacterRange:)"
}
-->

# addTemporaryAttribute(_:value:forCharacterRange:)

Adds a temporary attribute to the characters in the specified range.

```
func addTemporaryAttribute(_ attrName: NSAttributedString.Key, value: Any, forCharacterRange charRange: NSRange)
```

## Parameters

`attrName`

The name of a temporary attribute.

`value`

The temporary attribute value associated with `attrName`.

`charRange`

The range of characters to which the specified attribute-value pair applies.

## Discussion

Raises an <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException> if `attrName` or `value` is `nil`.

---

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)