Skip to content


Subversion checkout URL

You can clone with
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.


We love CocoaPods, so we recommend you use it.


Brandon Williams

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