Instance Method

enumerateAttribute:inRange:options:usingBlock:

Executes the specified block for each range of a particular attribute in the attributed string.

Declaration

- (void)enumerateAttribute:(NSAttributedStringKey)attrName inRange:(NSRange)enumerationRange options:(NSAttributedStringEnumerationOptions)opts usingBlock:(void (^)(id value, NSRange range, BOOL *stop))block;

Parameters

attrName

The name of the attribute to enumerate.

enumerationRange

The range over which the attribute values are enumerated.

opts

The options used by the enumeration. For possible values, see NSAttributedStringEnumerationOptions.

block

The block to apply to ranges of the specified attribute in the attributed string.

The block takes three arguments:

value

The value for the specified attribute.

range

The range of the attribute value in the attributed string.

stop

A reference to a Boolean value. The block can set the value to YES within the block to stop further processing of the attributed string.

Discussion

If this method is called by an instance of NSMutableAttributedString, mutation (deletion, addition, or change) is allowed only if the mutation is within the range provided to the block. After a mutation, the enumeration continues with the range immediately following the processed range, adjusting for any change in length caused by the mutation. For example, if block is called with a range starting at location N, and the block deletes all the characters in the provided range, the next call will also pass N as the location of the range.

See Also

Enumerating over Attributes in a String

- enumerateAttributesInRange:options:usingBlock:

Executes the specified block for each range of attributes in the attributed string.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software