TextKit 2 : replaceContents(in:with:) is not working

I have NsTextList and it has [NsTextListElement], I want to replace an NsTextListElement with other element like NsTextParagraph or NstextListElement or an AttributedString. For some reason the below method is not working at all. And I couldn't find any alternate way of replacing the elements

textLayoutManager.replaceContents(in: element.elementRange, with: NSAttributedString(string: "happy"))

That sounds strange. Would you mind to provide a minimal project that contains only the code relevant to the issue, with detailed steps to reproduce the issue? If you can do so, folks here may be able to help more effectively.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thanks for the reply, I have used a work around for this.

After researching about TextKit 2, I found out that some of APIs are not working and some are documented wrong.

  let paragraphElement = NSTextParagraph(attributedString: attrStr)
  textLayoutManager.replaceContents(in: element.elementRange, with: paragraphElement)
  

The above method is not working as documented, I found a work around for this problem by using other APIs of the TextKit 2.

    // creating an NSTextParagraph Element
    let paragraphElement = NSTextParagraph(attributedString: attrStr)

    //Getting the corresponding attributed String for the given element
    let attrString = textContentStorage.attributedString(for: paragraphElement)

    //replacing the attributed text using below method
    textContentStorage.textStorage?.replaceCharacters(in: nsrange, with: attrString!)
TextKit 2 : replaceContents(in:with:) is not working
 
 
Q