• 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
Help with simple EncodeObject & DecodeObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help with simple EncodeObject & DecodeObject


  • Subject: Help with simple EncodeObject & DecodeObject
  • From: email@hidden
  • Date: Tue, 28 May 2002 01:16:26 EDT

I admit it, I am having problems with the simplest of Cocoa document tasks, saving and opening data file.

What is the difference between using decodeObject/encodeObject and the various other flavors of the call (decodeDataObject, decodeRootObject, decodeNXObject, etc.)?

I have a simple document that contains a number of integers and strings (stored internally as NSString & NSNumber). To implement dataRepresentationOfType, I use NSArchiver and encode Object thus:

NSMutableData *a_data = nil;
NSArchiver *a_archiver = [[[NSArchiver alloc] initForWritingWithMutableData: [NSMutableData data]] autorelease];
if (a_archiver) {
[a_archiver encodeObject:someStr];
[a_archiver encodeObject:someNumber];
a_data = [a_archiver archiverData];
}
return a_data;

To implement loadDataRepresentation, I am using NSUnarchiver, decodeObject, and some already created Set methods:

if (data) {
NSUnarchiver *a_unarchiver = [NSUnarchiver unarchiveObjectWithData:data];
if (a_unarchiver) {
NSString* a_str = [a_unarchiver decodeObject];
NSNumber* a_number = [a_unarchiver decodeObject];
if ([a_unarchiver isAtEnd]) {
[self setMyString: a_str]
[self setMyNumber: a_number];
return YES;
}
}
}
return NO;

When I save, it seems to work, but when I read, I get various errors:

2002-05-28 01:11:48.605 d20 Edit[1278] *** +[NSUnarchiver unarchiveObjectWithData:]: extra data discarded
2002-05-28 01:11:48.611 d20 Edit[1278] *** -[NSshortNumber decodeObject]: selector not recognized
2002-05-28 01:11:48.651 d20 Edit[1278] *** -[NSshortNumber decodeObject]: selector not recognized

What am I doing wrong? Does anyone have source code examples of saving simple structures. Notice the data is NOT in a collections nor an array (I do not want to store it that way for a number of internal reasons). I thought the archivers/unarchivers were supposed to store the encoded information into a data object, to be passed to & from the file IO. I do not want to store the internal format of the object (ie. information regarding what type of object it is). I just want to store the internal data (the bytes of number or text).

Any ideas what I am missing?

Thanks!

Steve
_______________________________________________
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: Help with simple EncodeObject & DecodeObject
      • From: Marcel Weiher <email@hidden>
    • Re: Help with simple EncodeObject & DecodeObject
      • From: Carlos Weber <email@hidden>
  • Prev by Date: _NXSetCursorRect Error
  • Next by Date: Re: not having a new document be created on launch
  • Previous by thread: Re: _NXSetCursorRect Error
  • Next by thread: Re: Help with simple EncodeObject & DecodeObject
  • Index(es):
    • Date
    • Thread