<!--
{
  "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/NSAttributedString/attributes(at:longestEffectiveRange:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)attributesAtIndex:longestEffectiveRange:inRange:"
  },
  "title" : "attributes(at:longestEffectiveRange:in:)"
}
-->

# attributes(at:longestEffectiveRange:in:)

Returns the attributes for the character at the specified index and, by reference, the range where the attributes apply.

```
func attributes(at location: Int, longestEffectiveRange range: NSRangePointer?, in rangeLimit: NSRange) -> [NSAttributedString.Key : Any]
```

## Parameters

`location`

The index for which to return attributes. This value must not exceed the bounds of the receiver.

`range`

If non-`NULL`, upon return contains the maximum range over which the attributes and values are the same as those at `index`, clipped to `rangeLimit`.

`rangeLimit`

The range over which to search for continuous presence of the attributes at `index`. This value must not exceed the bounds of the receiver.

## Discussion

Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if `index` or any part of `rangeLimit` lies beyond the end of the receiver’s characters.

If you don’t need the range information, it’s far more efficient to use the [`attributes(at:effectiveRange:)`](/documentation/Foundation/NSAttributedString/attributes(at:effectiveRange:)) method to retrieve the attribute value.

For a list of possible attributes, see [`NSAttributedString.Key`](/documentation/Foundation/NSAttributedString/Key).

---

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)