• 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: Can't archive NSData :-(
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't archive NSData :-(


  • Subject: Re: Can't archive NSData :-(
  • From: Ali Ozer <email@hidden>
  • Date: Thu, 14 Jun 2001 23:33:41 -0700

Hmm, this looks like a bug in archiving some attributed strings created from HTML. That is, it doesn't have anything to do with NSData archiving; in fact, NSDatas do know how to archive themselves. Looks like HTMLDocument (object internally used by attributed strings when parsing HTML) is the one short on archiving skills.

Off the top of my head, I don't know whether there is a quick workaround.

Ali



On Thursday, June 14, 2001, at 06:39 PM, Michael P. Rogers wrote:

I've created an NSAttributedString using NSData, and this is causing problems when I try and archive it. Distilling the problem down to a simple example, when I issue these statements

NSAttributedString * okString = [[NSAttributedString alloc]initWithString:@"item 1"];

NSData * dataVersionOfHTML = [@"<H2>Text I want to display properly</H2>" dataUsingEncoding:NSASCIIStringEncoding];
NSAttributedString * notOKString = [[NSAttributedString alloc]initWithHTML:dataVersionOfHTML documentAttributes:NULL];
[ NSArchiver archiveRootObject:okString toFile:@"junkerOK.marion"];

[ NSArchiver archiveRootObject:notOKString toFile:@"junkerNotOK.marion"]; <======== error

the second call causes this error:

Jun 14 20:09:09 DocumentMunger[778] *** -[HTMLDocument encodeWithCoder:]: selector not recognized
Jun 14 20:09:09 DocumentMunger[778] An uncaught exception was raised

I *believe* that this is because NSData objects don't know how to encode themselves. But -- with all due respect to NSData objects in general -- I don't really care about this one, I'm just using it to create an NSAttributedString so I can display (and at this point save to disk) html that *looks* like html. (Aside: When I open up the NSAttributedString interface, it doesn't even *list* NSData: it's variables are

- (NSString *)string;
- (NSDictionary *)attributesAtIndex:(unsigned)location effectiveRange:(NSRangePointer)range;

-- so maybe my hypothesis about this being an NSData problem is incorrect??)

Anyway, I'd prefer to work exclusively with NSAttributedStrings, and not store NSStrings and then convert when I need to display them in an NSTextView. I get the feeling I'm supposed to subclass NSCoder, and override encodeDataObject, but this is getting increasingly messy. Is there an easier/better way?

Thanks for any suggestions/clarification,

Michael


  • Follow-Ups:
    • More info on NSDistributedNotification.
      • From: Charles Bennett <email@hidden>
References: 
 >Can't archive NSData :-( (From: "Michael P. Rogers" <email@hidden>)

  • Prev by Date: Re: Can't archive NSData :-(
  • Next by Date: Re: NDA?
  • Previous by thread: Re: Can't archive NSData :-(
  • Next by thread: More info on NSDistributedNotification.
  • Index(es):
    • Date
    • Thread