> let savedRtfd = originalString.rtfd(from:NSRange(0..<originalString.length))!

...
> recoveredAttachment.contents is still nil.


Your core problem is RTF/RTFD encoding. There's simply no guarantee those 
formats will preserve everything that's supported by the Apple text system, 
including NSTextAttachment data. Even features that are officially supported by 
RTF/RTFD might not be roundtripped if Apple didn't add support for it. 

A quick example: images in RTF data are discarded when loaded by 
NSAttributedString. That's despite the fact that images are completely 
supported by the RTF spec, NSTextAttachment, and even Apple's RTFD. It's just 
that Apple didn't bother with RTF.

Maybe there's another data format where Apple better handles attachment 
serialization? I don't know. But if I needed to reliably serialize all kinds of 
attachments I'd probably do it myself to be sure, since I don't recall seeing 
it mentioned explicitly.

~Martin Wierschin


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to