Želja Huber
Želja Huber

Reputation: 337

UITextView save attributed text

I have UITextView with some custom text. User can edit that text (change it, change some fonts, colour of text, highlight parts of text etc...) threw attributes of UITextView attributedText property.

When user is done with changing all that I need to save that newly created "Note" (whole changed text with attributes). How can I do that? Note that if there is 20 words in UITextView, 1, 5, 10,11,15th word can be red, 2,4,5 underlined and so on (so special ranges for each attribute) and I need to save all that on new place. Is it possible?

Thanks.

Upvotes: 0

Views: 778

Answers (1)

Léo Natan
Léo Natan

Reputation: 57060

NSAttributedString conforms to the NSCoding protocol, so you can use NSKeyedArchiver and NSKeyedUnarchiver to serialize and deserialize the attributed string to where you wish to save (user defaults, Core Data, etc.).

Upvotes: 3

Related Questions