1

I'm building a Social App where users can post a blog with content of type NSAttributedString (supporting Text-color, Bold, Italic,..). How should I send this NSAttributedString content to Server, so that when I receive it, I can populate it to the UITextview without any lost in decoration (Text-color, Bold, Italic, ..).

I tried sending an NSStringto server, but no luck, the text I received back is something unreadable when using [UITextView setAttributedString].

I guess there should be some kinds of encode and decode right?

Bista
  • 7,869
  • 3
  • 27
  • 55

1 Answers1

3

NSAttributedString conforms to NSCoding, so you can convert an NSAttributedString back and forth to NSData. It's been a while since I've used AFNetworking, but doesn't it have a way to transfer binary data? That seems like your best bet.

(NSAttributedString also has the ability to read from .rtf files on both Mac and iOS >= 7.0.

According to this thread on SO it's also possible to export the contents of an attributed string to rtf format, so that's another possibility.

Community
  • 1
  • 1
Duncan C
  • 128,072
  • 22
  • 173
  • 272