0

I want to send the attributedString to the server along with all attribute information and then receive this on another device and display the attributedString in UITextView again. I have created a Transformable attribute in CoreData with NSAttributedString as custom class. i get the UITextView attributedString and save it in CoreData and later on retrieve it and display back on UITextView. This all works fine, however my use case requires me to send the formatted text along with all attributes information to server using REST API. I tried following solutions but none of them worked:

  • Convert NSAttributedString to String (Problem: it removes the formatting information)
  • serialise NSAttributedString object using NSKeyedArchiver.archivedData and then send the resultant Data to server (Problem: I get error in POST method)
  • serialise NSAttributedString and convert the resultant Data to string using testString.data(using: String.Encoding.utf8) (Problem: When i try to convert this string back to Data i get error)

Can anybody guide me in this, if i am approaching this problem the right way or not? I am open to upgrading to latest Swift version if there is any new feature which i can use to solve this problem. Any kind of help is appreciated.

Thank you

Affan

Affan Toor
  • 11
  • 1

1 Answers1

0

Convert NSAttributedString to HTML. I think solved your problem.

How do i convert NSAttributedString into HTML string?

Display HTML data in a label or textView

Mohammad Razipour
  • 3,643
  • 3
  • 29
  • 49
  • 1
    thanks. converting the attributed string to HTML could actually solve my problem. my only concern is that if any of the styling is lost or altered after the HTML is converted back to attributed string. i will test this. thank you again for your response. cheers – Affan Toor Nov 26 '19 at 19:59