• 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
Re: Adding <NSCoding> to NSTextStorage, or not.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Adding <NSCoding> to NSTextStorage, or not. (From: Kirk Kerekes <email@hidden>)

  • Prev by Date: Re: cocoa-dev digest, Vol 2 #672 - 18 msgs
  • Next by Date: Re: Comment on archiving as an application file format
  • Previous by thread: Adding <NSCoding> to NSTextStorage, or not.
  • Next by thread: Re: Adding <NSCoding> to NSTextStorage, or not.
  • Index(es):
    • Date
    • Thread