---
title: "attribute(_:at:effectiveRange:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsattributedstring/attribute(_:at:effectiverange:)"
---

# attribute(_:at:effectiveRange:)

Returns the value for an attribute with the specified name of the character at the specified index and, by reference, the range where the attribute applies.

## Declaration

```swift
func attribute(_ attrName: NSAttributedString.Key, at location: Int, effectiveRange range: NSRangePointer?) -> Any?
```

## Parameters

- `attrName`: The name of an attribute.
- `location`: The index for which to return attributes. This value must not exceed the bounds of the receiver. important: Raises an doc://com.apple.foundation/documentation/Foundation/NSExceptionName/rangeException if index lies beyond the end of the receiver’s characters.
- `range`: If non-NULL: If the named attribute exists at index, upon return aRange contains a range over which the named attribute’s value applies. If the named attribute does not exist at index, upon return aRange contains the range over which the attribute does not exist. The range isn’t necessarily the maximum range covered by attributeName, and its extent is implementation-dependent. If you need the maximum range, use doc://com.apple.foundation/documentation/Foundation/NSAttributedString/attribute(_:at:longestEffectiveRange:in:). If you don’t need this value, pass NULL.

## Return Value

Return Value The value for the attribute named attrName of the character at location, or nil if there is no such attribute.

## Discussion

Discussion For a list of possible attributes, see NSAttributedString.Key.

## See Also

### Getting attributes for a range of text

- [attributes(at:effectiveRange:)](foundation/nsattributedstring/attributes(at:effectiverange:).md)
- [attributes(at:longestEffectiveRange:in:)](foundation/nsattributedstring/attributes(at:longesteffectiverange:in:).md)
- [attribute(_:at:longestEffectiveRange:in:)](foundation/nsattributedstring/attribute(_:at:longesteffectiverange:in:).md)
- [enumerateAttribute(_:in:options:using:)](foundation/nsattributedstring/enumerateattribute(_:in:options:using:).md)
- [enumerateAttributes(in:options:using:)](foundation/nsattributedstring/enumerateattributes(in:options:using:).md)
- [NSAttributedString.EnumerationOptions](foundation/nsattributedstring/enumerationoptions.md)
