Contents

enumerateTextElements(from:options:using:)

Enumerates text elements starting at the text location you provide.

Declaration

func enumerateTextElements(from textLocation: (any NSTextLocation)?, options: NSTextContentManager.EnumerationOptions = [], using block: (NSTextElement) -> Bool) -> (any NSTextLocation)?

Parameters

  • textLocation:

    The Nstextlocation at which to start the enumeration.

  • options:

    One of the possible NSTextElementProviderEnumerationOptions directions.

  • block:

    A block you use to evaluate whether to continue the enumeration or tell the method to stop. Return false to end the enumeration process.

Return Value

An NSTextLocation.

Discussion

If textLocation is nil, the method uses documentRange.location for forward enumeration and documentRange.endLocation for reverse enumeration. When enumerating backward, the method starts with the element preceding the one containing textLocation. If enumerated at least one element, it returns the edge of the enumerated range.

The enumerated range might not match the range of the last element returned. It enumerates the elements in the sequence, but it can skip a range (it can limit the maximum number of text elements enumerated for a single invocation or hide some elements from the layout).

Returning NO or false from block breaks out of the enumeration.

See Also

Accessing and updating the text