Adding <NSCoding> to NSTextStorage, or not.
Adding <NSCoding> to NSTextStorage, or not.
- Subject: Adding <NSCoding> to NSTextStorage, or not.
- From: Kirk Kerekes <email@hidden>
- Date: Fri, 24 May 2002 19:01:47 -0500
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) and I suspect that is because the class type of NSTextStorage is
never stored in the resulting stream, and NSTextStorage declares instance
variables that would simply make it a larger object than NSAttributedString.
So when it gets unarchived, the unarchiver creates the wrong size object,
and succeeding operations generate illegal memory accesses.
So I attempted to add the <NSCoding> protocol to NSTextStorage via a
Category.
@interface NSTextStorage (TextStorageCoding ) <NSCoding>
- adding what seems to be the appropriate implementation of encodeWithCoder
and initWithCoder (at the moment they just call the [super] versions)
I got this to compile, link and crash. Looking at the resulting file, it
still doesn't appear that NSTextStorage is "in there" anywhere -- just
NSAttributedString.
I have gotten around this hurdle through a side-door -- I just use
RTFDFromRange:documentAttributes: to serialize the contents of
NSTextStorage, and use [[NSTextStorage alloc]
initWithRTFD:documentAttributes:] to reconstitute it.
But it bugs me that it didn't work the way it "oughta".
Any wisdom on why it doesn't?
_______________________________________________
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.