• 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: Moving to Keyed Archiving
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Moving to Keyed Archiving


  • Subject: Re: Moving to Keyed Archiving
  • From: Chris Kane <email@hidden>
  • Date: Sun, 31 Aug 2003 11:36:28 -0700

On Aug 27, 2003, at 4:17 AM, Drew McCormack wrote:

On Tuesday, August 26, 2003, at 09:32 PM, Drew McCormack wrote:

On Tuesday, August 26, 2003, at 05:58 PM, Justin Anderson wrote:

There's one idea provided by Apple in the Cocoa Docs at <http://developer.apple.com/documentation/Cocoa/Conceptual/ Archiving/Tasks/convertingclasses.html>.

What you're looking for is down towards the bottom of the page, right before the sample code. The gist of it is that you should test for -containsValueForKey: (available in both NSKeyedUnarchiver and NSCoder). Apple's sample code on there is for NSCoder's -initWithCoder, but here's basically what you'd need to do for your -loadDataRepresentation: ofType:

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSKeyedUnarchiver *keyedUnarchiver = [[[NSKeyedUnarchiver alloc]
initForReadingWithData:data] autorelease];
NSUnarchiver *unarchiver = [[[NSUnarchiver alloc]
initForReadingWithData:data] autorelease];

Unfortunately this doesn't work. If the data is not in keyed format, you get the following


2003-08-26 21:21:25.592 Trade Strategist[13644] CFLog (0):
CFPropertyListCreateFromXMLData(): plist parse failed; the data is not proper UTF-8. The file name for this data could be:
com.apple.LaunchServices.00039363bc02.plist -- /Users/drew/Library/Preferences/ByHost/
The parser will retry as in 10.1, but the problem should be corrected in the plist.

Trade Strategist has exited due to signal 11 (SIGSEGV).


Unfortunately you don't get a nil object returned, or an NSException raised, it just dies with a signal 11. Bad.
How can I get around this? I need to be able to find out what is in the data without crashing my program.

Drew

------
To answer my own post, I did manage to come up with a solution. Here it is, in case it helps someone.

If you try to initialize an NSKeyedUnarchiver with non-keyed data, it will crash. Bad Apple!!! I regard this as a bug. You should get a chance to recover, via an NSException or by returning nil.

So I tried this:

#import <Foundation/Foundation.h>
int main() {
[NSAutoreleasePool new];
id args = [[NSProcessInfo processInfo] arguments];
int idx;
for (idx = 1; idx < [args count]; idx++) {
id a = [args objectAtIndex:idx];
id data = [NSData dataWithContentsOfFile:a];
NS_DURING
id u = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
[u release];
NS_HANDLER
NSLog(@"Got exception: %@", localException);
NS_ENDHANDLER
}
return 0;
}

and get:

2003-08-31 11:27:44.341 a.out[530] CFLog (0):
CFPropertyListCreateFromXMLData(): plist parse failed; the data is not proper UTF-8. The file name for this data could be:
./Utilities/Terminal.app/Contents/Resources/zh_TW.lproj/Terminal.nib/ objects.nib
The parser will retry as in 10.2, but the problem should be corrected in the plist.
2003-08-31 11:27:44.344 a.out[530] Got exception: *** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x4, 0xb, 0x74, 0x79, 0x70, 0x65, 0x64, 0x73)


That is, I get an exception raised. I get this for all 6638 objects.nib files under my current /Applications folder. I also tried the program with "/bin/*" and "/usr/share/zoneinfo/America/Chicago" and "/usr/lib/libobjc.dylib" and "/mach_kernel" and a few other choices. But NSKeyedUnarchiver only seems to have a few changes to squash some compiler warnings in that area in the Panther version I'm using, from 10.2. Perhaps the problem was lower.


Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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: 
 >Re: Moving to Keyed Archiving (From: Drew McCormack <email@hidden>)

  • Prev by Date: String encoding question
  • Next by Date: Re: Logging entry/exit into methods &/|| functions
  • Previous by thread: Re: Moving to Keyed Archiving
  • Next by thread: Frustrating NSMenu problem
  • Index(es):
    • Date
    • Thread