Contents

enumerateTextLayoutFragments(from:options:using:)

Enumerates the text layout fragments starting at the specified location.

Declaration

func enumerateTextLayoutFragments(from location: (any NSTextLocation)?, options: NSTextLayoutFragment.EnumerationOptions = [], using block: (NSTextLayoutFragment) -> Bool) -> (any NSTextLocation)?

Parameters

  • location:

    The location where youstart the enumeration.

  • options:

    One or more of the available Enumerationoptions.

  • block:

    A closure you provide that determines if the enumeration finishes early.

Return Value

An NSTextLocation, or nil.

Discussion

If textLocation is nil, the method starts at self.textContentManager.documentRange.location.The method uses self.documentRange.endLocation for reverse enumeration. When enumerating backward, it starts with the fragment preceding the one containing textLocation. If the method enumerates at least one fragment, 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. For example, it can limit the maximum number of text elements the method enumerates for a single invocation or hide some elements from the layout.

Returning false from block breaks out of the enumeration.

See Also

Causing layout generation