TextKit 2 - How to render multiple fragments in one NSTextParagraph?

Hello TextKit 2 development team,

I am trying to render a paragraph of text with different styles for specific words. I have carefully reviewed the sample code provided in the documentation but I couldn't find any method to display NSTextLayoutFragment with different styles in a single NSTextParagraph.

Currently, I am using

NSTextContentStorageDelegate.textContentStorage(:textParagraphWith:)

to output the corresponding NSTextParagraph, and then using

NSTextLayoutManagerDelegate.textLayoutManager(:textLayoutFragmentFor:in:)

to output the corresponding TextLayoutFragment. However, this only allows me to customize the style on a paragraph, while what I need is to customize the style of certain words within the paragraph.

I have guessed that I can achieve this by specifying NSTextLineFragment properties, but in reality, it does not display any content. Can you please guide me on how to accomplish this task?

TextKit 2 - How to render multiple fragments in one NSTextParagraph?
 
 
Q