<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableAttributedString/addAttributes(_:range:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableAttributedString(im)addAttributes:range:"
  },
  "title" : "addAttributes(_:range:)"
}
-->

# addAttributes(_:range:)

Adds the given collection of attributes to the characters in the specified range.

```
func addAttributes(_ attrs: [NSAttributedString.Key : Any] = [:], range: NSRange)
```

## Parameters

`attrs`

A dictionary containing the attributes to add. Attribute keys can be supplied by another framework or can be custom ones you define. For information about the system-supplied attribute keys, see the Constants section in [`NSAttributedString`](/documentation/Foundation/NSAttributedString).

`range`

The range of characters to which the specified attributes apply.

## Discussion

You may assign any name/value pair you wish to a range of characters. Raises an [`invalidArgumentException`](/documentation/Foundation/NSExceptionName/invalidArgumentException) if `attrs` is `nil` and an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if any part of `range` lies beyond the end of the receiver’s characters.

---

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)