Re: Adding <NSCoding> to NSTextStorage, or not.
Re: Adding <NSCoding> to NSTextStorage, or not.
- Subject: Re: Adding <NSCoding> to NSTextStorage, or not.
- From: "Timothy J. Wood" <email@hidden>
- Date: Fri, 24 May 2002 19:20:48 -0700
On Friday, May 24, 2002, at 05:01 PM, Kirk Kerekes wrote:
Although NSTextStorage is descended from NSAttributedString, which
implements <NSCoding>, NSTextStorage does not.
I know that relying on the inherited implementation doesn't work
('cause I tried it)...
I don't know why the subclass wouldn't work since it should be
possible to implement it from the superclass... anyway, implementing it
yourself should be trivial if you just a plain attributed string to do
the dirty work.
For archiving:
NSAttributedString *archiveString;
NSTextStorage *textStorage;
NSData *data;
archiveString = [[NSAttributedString alloc]
initWithAttributedString: textStorage];
data = [NSArchiver archivedDataWithRootObject: archiveString];
[archiveString release];
and this for unarchiving:
NSAttributedString *unarchiveString;
NSTextStorage *textStorage;
NSData *data;
unarchiveString = [NSUnarchiver unarchiveObjectWithData: data];
[textStorage beginEditing];
[textStorage setAttributedString: unarchiveString];
[textStorage endEditing];
This assumes, of course, that the archive/unarchive support in
NSAttributedString works at all. Also, it assume that all the
attributes on the string implement NSCoding too :)
Also, this will be less efficient than having the NSTextStorage
version work.
-tim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.