Adds methods to NSAttributedString for conversion to NSData and back.
Switch branches/tags
Nothing to show
Latest commit f9271bf Apr 8, 2012 @mbrandonw Added a dependency on my OPCoreText repository, and thus greatly simp…
…lified the encoding and decoding methods of NSAttributedString.
Failed to load latest commit information.


#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