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

Can't archive NSData :-(


  • Subject: Can't archive NSData :-(
  • From: "Michael P. Rogers" <email@hidden>
  • Date: Thu, 14 Jun 2001 20:39:18 -0500

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
--
---------------------------------
Dr. Michael Rogers
e-mail: email@hidden
Phone: 217-424-6327

For information about Computer Science at Millikin University, visit http://math.millikin.edu
For information about astronomy, check out http://twincityamateurastronomers.org


  • Follow-Ups:
    • Re: Can't archive NSData :-(
      • From: Ali Ozer <email@hidden>
    • Re: Can't archive NSData :-(
      • From: Brendan Younger <email@hidden>
  • Prev by Date: Re: Cocoa/EOF for non-enterprise apps Re: proof of cocoa
  • Next by Date: Re: loginwindow scripts
  • Previous by thread: Re: Finding an image like [NSImage imageNamed:] but not in bundle?
  • Next by thread: Re: Can't archive NSData :-(
  • Index(es):
    • Date
    • Thread