• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Adding <NSCoding> to NSTextStorage, or not.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Adding <NSCoding> to NSTextStorage, or not.
      • From: jerome LAURENS <email@hidden>
    • Re: Adding <NSCoding> to NSTextStorage, or not.
      • From: "Timothy J. Wood" <email@hidden>
  • Prev by Date: Re: [OT] Re: Constructive Ideas
  • Next by Date: Array question, Obj-C
  • Previous by thread: Re: [OT] Re: Constructive Ideas
  • Next by thread: Re: Adding <NSCoding> to NSTextStorage, or not.
  • Index(es):
    • Date
    • Thread