Instance Method

attribute(_:at:effectiveRange:)

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.

Declaration

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.

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 attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass NULL.

Return Value

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

Discussion

For a list of possible attributes, see Character Attributes.

See Also

Retrieving Attribute Information

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

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

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.