attribute(_:at:longestEffectiveRange:in:)
Returns the value for the attribute with the specified name of the character at the specified index and, by reference, the range where the attribute applies.
Declaration
func attribute(_ attrName: NSAttributedString.Key, at location: Int, longestEffectiveRange range: NSRangePointer?, in rangeLimit: NSRange) -> Any?Parameters
- attrName:
The name of an attribute.
- location:
The index at which to test for
attributeName. - range:
If non-
NULL:If the named attribute exists at
index, upon returnaRangecontains the full range over which the value of the named attribute is the same as that atindex, clipped torangeLimit.If the named attribute does not exist at
index, upon returnaRangecontains the full range over which the attribute does not exist, clipped torangeLimit.
If you don’t need this value, pass
NULL. - rangeLimit:
The range over which to search for continuous presence of
attributeName. This value must not exceed the bounds of the receiver.
Return Value
The value for the attribute named attributeName of the character at index, or nil if there is no such attribute.
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 longest effective range, it’s far more efficient to use the attribute(_:at:effectiveRange:) method to retrieve the attribute value.
For a list of possible attributes, see NSAttributedString.Key.