<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/enumerateAttributes(in:options:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)enumerateAttributesInRange:options:usingBlock:"
  },
  "title" : "enumerateAttributes(in:options:using:)"
}
-->

# enumerateAttributes(in:options:using:)

Executes the specified closure or block for each range of attributes in the attributed string.

```
func enumerateAttributes(in enumerationRange: NSRange, options opts: NSAttributedString.EnumerationOptions = [], using block: ([NSAttributedString.Key : Any], NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)
```

## Parameters

`enumerationRange`

The range over which the attributes are enumerated.

`opts`

The options used by the enumeration. For possible values, see [`NSAttributedString.EnumerationOptions`](/documentation/Foundation/NSAttributedString/EnumerationOptions).

`block`

The closure or block to apply to ranges of attributes in the attributed string, taking three arguments:

- A dictionary of attribute values keyed by name.
- The range of the attribute values in the attributed string.
- A reference to a Boolean value, which you can set to <doc://com.apple.documentation/documentation/Swift/true> within the closure to stop further processing of the attributed string.

## Discussion

If this method is called by an instance of [`NSMutableAttributedString`](/documentation/Foundation/NSMutableAttributedString), mutation (deletion, addition, or change) is allowed only if the mutation is within the range provided to the block. After a mutation, the enumeration continues with the range immediately following the processed range, adjusting for any change in length caused by the mutation. For example, if `block` is called with a range starting at location `N`, and the block deletes all the characters in the provided range, the next call will also pass `N` as the location of the range.

---

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)