Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

20 lines (13 sloc) 1.108 kB

NSAttributedString+Encoding - To NSData and back

This category adds two methods to NSAttributedString that allows you to easily convert instances to NSData and back. For example,

NSAttributedString *string = [[NSAttributedString alloc] initWithString:... attributes:...];
NSData *encoded = [string convertToData];
NSAttributedString *decoded = [NSAttributedString attributedStringWithData:encoded];

Unfortunately, it is not necessarily true that [string isEqualToAttributedString:decoded] due to some unsupported features of attributed strings. Right now we do not properly encode glyph attributes, run delegates (whatever the hell those are), and the tab stops specificer of paragraph styles. However, the decoded string is similar enough to the original that you probably won't even notice when rendering.

Installation

We love CocoaPods, so we recommend you use it.

Author

Brandon Williams
@mbrandonw
brandon@opetopic.com
www.opetopic.com

Jump to Line
Something went wrong with that request. Please try again.