Instance Method

attributes(at:longestEffectiveRange:in:)

Returns the attributes for the character at a given index, and by reference the range over which the attributes apply.

Declaration

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

Parameters

index

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

aRange

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 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:) method to retrieve the attribute value.

For a list of possible attributes, see Character Attributes.

See Also

Retrieving Attribute Information

func attribute(NSAttributedString.Key, at: Int, effectiveRange: NSRangePointer?) -> Any?

Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.

func attribute(NSAttributedString.Key, at: Int, longestEffectiveRange: NSRangePointer?, in: NSRange) -> Any?

Returns the value for the attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.