Created
January 10, 2012 16:46
-
-
Save pita5/1589961 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface MWPersistableAttributedString : NSMutableAttributedString <NSCoding> | |
@end | |
@implementation MWPersistableAttributedString | |
- (void)encodeWithCoder:(NSCoder *)aCoder | |
{ | |
[aCoder encodeObject:[self string] forKey:@"string"]; | |
NSMutableArray *attributes = [NSMutableArray array]; | |
[self enumerateAttributesInRange:NSMakeRange(0, [self length]) | |
options:0 | |
usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) | |
{ | |
// This does nothing, nothing to see here.... | |
NSLog(@"range %@", NSStringFromRange(range)); | |
NSLog(@"attrs %@", attrs); | |
}]; | |
[aCoder encodeObject:attributes forKey:@"attributes"]; | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
if ((self = [self initWithString:[aDecoder decodeObjectForKey:@"string"]])) | |
{ | |
for (NSDictionary *attributes in [aDecoder decodeObjectForKey:@"attributes"]) | |
{ | |
[self addAttributes:nil | |
range:NSMakeRange(0, 0)]; | |
} | |
} | |
return self; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableAttributedString *mutText = [[[MWPersistableAttributedString alloc] initWithString:@"hello world"] autorelease]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment