Executes the specified block for each range of attributes in the attributed string.
SDKs
- iOS 4.0+
- macOS 10.6+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
- (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(NSAttributed String Enumeration Options)opts usingBlock:(void (^)(NSDictionary<NSAttributed String Key, id> *attrs, NSRange range, BOOL *stop))block;
Parameters
enumerationRange
The range over which the attributes are enumerated.
opts
The options used by the enumeration. For possible values, see
NSAttributed
.String Enumeration Options block
The block to apply to ranges of attributes in the attributed string.
The block takes three arguments:
- attrs
A dictionary of attribute values keyed by name.
- range
The range of the attribute values 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 NSMutable
, 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.