Skip to content

Text Copy Stops Working: "Cannot load representation of type com.apple.uikit.attributedstring" #405

@meaning-matters

Description

@meaning-matters

Thank you for contributing to MarkdownUI!

Before you submit an issue, please complete the report with all the relevant details for your bug and go through every item in the checklist.

Describe the bug
First text copy works, also formatted sections like code. But at some point, after perhaps 10 or 15 copies, the Xcode console prints:

...saving pasteboard failed with error: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type com.apple.uikit.attributedstring" UserInfo={NSLocalizedDescription=Cannot load representation of type com.apple.uikit.attributedstring, NSUnderlyingError=0x3036f3a80 {Error Domain=NSCocoaErrorDomain Code=4866 "The data couldn’t be written because it isn’t in the correct format." UserInfo={NSUnderlyingError=0x3036f3ba0 {Error Domain=NSCocoaErrorDomain Code=4864 "This decoder will only decode classes that adopt NSSecureCoding. Class '__NSCFType' does not adopt it." UserInfo={NSDebugDescription=This decoder will only decode classes that adopt NSSecureCoding. Class '__NSCFType' does not adopt it.}}}}}

My code (text is a String):

                            Markdown(text)
                                .textSelection(.enabled)
                                .padding(10)
                                .background(Color.gray.opacity(0.2))
                                .cornerRadius(10)

After that text copy no longer works; neither on texts without formatting that were able to be copied earlier. Each time the Copy menu button is tapped, above error is printed.

Checklist

  • I can reproduce this issue with a vanilla SwiftUI project.
  • I can reproduce this issue using the main branch of this package.
  • This bug hasn't been addressed in an existing GitHub issue.

Steps to reproduce
Explanation of how to reproduce the incorrect behavior. This could include an attached project, a link to code, or a Markdown-formatted text exhibiting the issue.

  1. Hold down finger on a piece of Markdown view content until Copy | Share... menu appears.
  2. Tap the Copy button.
  3. Paste text somewhere. Perhaps not needed; didn't try yet.
  4. Repeat 1, 2, and 3 for different texts on different screens and at some point the text will no longer be copied to the pasteboard and step 2 prints the warning on Xcode console.

Might happen earlier when selecting a formatted text, like a code block; but not sure.

Expected behavior
Tapping the Copy menu button should always copy the text.

Screenshots
If applicable, add screenshots to help explain your problem.

Version information

  • MarkdownUI: 2.4.1
  • OS: Device iOS 18.4 and iOS 18.1.1
  • Xcode: 16.3

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions